PDA

View Full Version : MessageBox focus/defaultButton



manoj123
2 Jun 2011, 5:01 AM
Hi,

Have read numerous threads on how to set a defaultButton or focus to 'No' button on MessageBox. However could not manage to get this feature right. Below is my sample code.


var dlg = Ext.MessageBox.confirm('Confirm', 'Are you sure you want to do that?',showResult);
console.log(dlg.getDialog().buttons[2]);
dlg.getDialog().buttons[2].focus(true,20);

Also tried without any parameters to focus method. Doesn't work both on FF and IE.

manoj123
2 Jun 2011, 7:51 AM
no responses? I thought it would be very simple solution /:)

friend
2 Jun 2011, 8:24 AM
There's probably a simpler/better way, but this works:



var dlg = Ext.MessageBox.confirm('Confirm', 'Are you sure you want to do that?');
(function() { dlg.getDialog().buttons[2].focus(true,20); }).defer(50);


Note that you may need to increase the defer time, in case of older/slower machines which may render less quickly/effciently.

manoj123
2 Jun 2011, 8:34 AM
thanks a lot. defer option did the trick. However there is no visual indication of 'No' button being selected?

friend
2 Jun 2011, 8:41 AM
Try increasing the defer time and/or the focus time.