PDA

View Full Version : Simple feature: MessageBox default button



cgraf
10 Jul 2008, 7:01 AM
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

fullinet
5 May 2010, 8:32 AM
I would like that too

micgala
6 May 2010, 12:00 AM
That is a good idea, probably.

But anyway, there is a way to change that behaviour via 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.

sven
7 May 2010, 4:03 AM
I like this idea. In GXT2.2, if there are no or cancel buttons, they will have the focus.

fullinet
7 May 2010, 7:02 AM
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() :



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));
}
}

WesleyMoy
18 Aug 2010, 10:58 PM
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:


MessageBox alertBox = MessageBox.alert("Alert Box", "Hey, I'm alerting you!", null);
alertBox.getDialog.getButtonById(Dialog.NO).focus();