1. #1
    Ext User
    Join Date
    Feb 2008
    Posts
    8
    Vote Rating
    0
    cgraf is on a distinguished road

      0  

    Default Simple feature: MessageBox default button

    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
    fullinet is on a distinguished road

      0  

    Default


    I would like that too

  3. #3
    Sencha User
    Join Date
    Nov 2008
    Location
    Vienna - Austria
    Posts
    867
    Vote Rating
    1
    micgala is on a distinguished road

      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
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      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
    fullinet is on a distinguished road

      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
    WesleyMoy is on a distinguished road

      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