View Full Version : How to keep focus in MessageBox

5 Dec 2011, 1:08 AM
I am using EditorGridPanel with cellEditor which acts nearly like Excel. We implemented Arrow Keys to move among rows and columns.While validating a row, if it does not match the validation rule we show a MessageBox and hope that focus does not move if it is not valid. But, after the MessageBox shows - focus moves to the next row/column. Another problem is, user have to click in the OK button of the MessageBox to remove that from screen. Can we have the focus on the invalid column editor and also focus on the MessageBox OK button - so that user can press Enter to hide the message and continue entry?

5 Dec 2011, 1:21 AM
the DOM only allows one element to have focus at a time.

if you do not want an ok button, then the messagebox is not a good approach.
there are some ux out there like toastMessage which should fit better.
i am not sure though, if one of the ux is already ported to ext 4.

also i am not sure if you are using 4, since this is not the correct forum for version specific questions.

6 Dec 2011, 4:58 AM
I am Anwar's colleague...we are developing in Ext 3.x. Actually we do want the Messagebox to have the focus. But because of async nature of messagebox the code continues and focus moves to the next control. Can we have the focus on the messagebox OK button and after pressing Enter - the code after wards should continue.

Think about the scenario when you enter 500 in a textbox, but the box has limits imposed say 100-200 - and you should show a message about the error - then after pressing OK - you would set the focus back to the problem box.

Hope I made it clear.

6 Dec 2011, 5:21 AM
you can dispaly the validation errors also in tooltips for the grid editor fields.

but in your usecase: before opening the dialog, save the cell (row+column) and after closing the dialog call:


6 Dec 2011, 5:39 AM
Dear Tobiu,

We cannot save the cell when validation fails, rather we are showing the messagebox to let the user know of the validation error.

The main problem is - how to take focus on the mesagebox OK button?

6 Dec 2011, 5:48 AM
the msgbox has a default focus on the ok button (it closes when you hit enter).

so, as i suggested: before opening it, check which cell has the focus, save it and restore it as mentioned above.

6 Dec 2011, 6:41 AM
As of I know messageboxes are async. In our case, I don't know why, the messagebox loses focus and control moves to the next control (which is actually editor in the grid cell). If you want to see the real implementation, browse to -


Select Facility: Kamfishane, Month: July, Year: 2011 - then press Show button. Then on any row of the grid E column (Closing Balance) type any number (say 200) and press Enter/Tab - then a messagebox will show - meaning calculation error - but focus will move to next row. Now you have to click on the OK button to continue.

Hope you have time to investigate the issue and assist workaround.

11 Dec 2011, 6:15 PM
Nice forum.. Lots of tutorial..