Results 1 to 6 of 6

Thread: Simple feature: MessageBox default button

  1. #1
    Ext User
    Join Date
    Feb 2008
    Posts
    8
    Vote Rating
    0
      0  

    Default Simple feature: MessageBox default button

    Hi,

    In the MessageBox.confirm method the button "Yes" is always the default. It should be nice to set the "No" button as default.

    I say that because of some ergonomics theory: the default button should cancel the user operation.

    For instance, I have a messagebox like "Confirm delete? Yes or no". The yes button is default. If the user hits enter without intention, the record is deleted asap. It should cancel the delete.

    Hope you undertand!

    cgraf

  2. #2
    Sencha User
    Join Date
    Mar 2010
    Posts
    13
    Vote Rating
    0
      0  

    Default

    I would like that too

  3. #3
    Sencha User
    Join Date
    Nov 2008
    Location
    Vienna - Austria
    Posts
    877
    Vote Rating
    1
      0  

    Default

    That is a good idea, probably.

    But anyway, there is a way to change that behaviour via code:

    PHP Code:
    messageBox.getDialog().setFocusWidget(messageBox.getDialog().getButtonBar().getItemByItemId(Dialog.NO)); 
    The problem is that you need to instantiate the MessageBox (and it is normally not used like this, but using the static methods).

    Regards,
    Michel.

  4. #4
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976
    Vote Rating
    132
      0  

    Default

    I like this idea. In GXT2.2, if there are no or cancel buttons, they will have the focus.

  5. #5
    Sencha User
    Join Date
    Mar 2010
    Posts
    13
    Vote Rating
    0
      0  

    Default

    Yes, it would be nice but if you could allow to set an arbitrary focus button too, it would be better.... Something like this in MessageBox#getDialog() :

    Code:
    if (getButtons() != null) {
      if (defaultFocusButton != null && getButtons().contains(defaultFocusButton)) {
        dialog.setFocusWidget(dialog.getButtonBar().getItemByItemId(defaultFocusButton));  
      } else if (getButtons().contains(Dialog.NO)) {
        dialog.setFocusWidget(dialog.getButtonBar().getItemByItemId(Dialog.NO));
      } else if (getButtons().contains(Dialog.CANCEL)) {
        dialog.setFocusWidget(dialog.getButtonBar().getItemByItemId(Dialog.CANCEL));
      } else if (getButtons().contains(Dialog.YES)) {
        dialog.setFocusWidget(dialog.getButtonBar().getItemByItemId(Dialog.YES));
      } else if (getButtons().contains(Dialog.OK)) {
        dialog.setFocusWidget(dialog.getButtonBar().getItemByItemId(Dialog.OK));
      }
    }

  6. #6
    Sencha User WesleyMoy's Avatar
    Join Date
    Oct 2009
    Location
    Redwood City, California
    Posts
    402
    Vote Rating
    2
      0  

    Default

    Quote Originally Posted by micgala View Post
    PHP Code:
    messageBox.getDialog().setFocusWidget(messageBox.getDialog().getButtonBar().getItemByItemId(Dialog.NO)); 
    The problem is that you need to instantiate the MessageBox (and it is normally not used like this, but using the static methods).
    Most of the static methods you would call to show a MessageBox (alert, confirm, progress, prompt) do in fact return a MessageBox object, so it's not that bad. In fact, you can even further simplify your snippet of code quite a bit:

    PHP Code:
    MessageBox alertBox MessageBox.alert("Alert Box""Hey, I'm alerting you!"null);
    alertBox.getDialog.getButtonById(Dialog.NO).focus(); 
    Last edited by WesleyMoy; 18 Aug 2010 at 11:00 PM. Reason: Code prettier

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •