View Full Version : Row editor button steals focus

11 Jul 2012, 7:05 AM
I have overridden the row editor to add two buttons. One button, when pressed takes the cell that has focus and overwrites the values in the cells to the right of it. However, the cell would lose its focus when the button was pushed. On a suggestion, I overwrote the onMouseDown and onMouseUp, adding e.stopEvent() to keep the event from continuing up (it works, just not for my row editor). It works. Sometimes--and somewhat randomly.

After overwriting the values, the field that had focus (and lost it when the button was clicked), does not regain focus when I click on it until I move the cursor (the cursor remains in the cell after the button click). I can't trace what happens after the event handler, and I have no idea how to investigate what's going on. Suggestions?

11 Jul 2012, 8:50 AM
i think stopping the event is a bad suggestion for the hope the last focussed field/cell will regain its focus. Better to save the state of the last focussed field - on a on blur or focus event- and focus it again when youre ready doing your stuff.

Clicking a button is just end of focus field. Stopping events is then gambling on behaviour.

11 Jul 2012, 1:21 PM
Thank you for your advice. I think I explained my problem badly. When the button is clicked, I need to know which cell has focus so that its value can be copied into the cells following it. Currently, the method I'm using is spotty at best.

11 Jul 2012, 1:29 PM
Isn it an option to set a focus listener on the fields. OnFocus of the field you set a reference on a currentfocus variable. If the field looses focus, because of clicking the button, you just read the currentfocus variable.

This is the way I keep track of these things.

When youre done setting the values, just set focus back on the field referenced by the currentfocus variable.

11 Jul 2012, 2:17 PM
I can put a listener on each field, yes, but I can't find a good way of doing so. Everything I've looked at seems messy. And wouldn't you have to put an onblur event on the editor to erase the currentfocus variable?

11 Jul 2012, 11:09 PM
There are multiple ways to put listeners on the fields. That a matter of programdesign. Erasing the variable is not needed. You only have to know the last focussed field. Closing the editor for possible can erase the variable.

16 Jul 2012, 6:22 AM
I'm not 100% certain what I will be doing (I switched projects), so I will have to hold off on marking an answer. But your advice did help.