View Full Version : How to prevent loosing focus for grid cell?

7 Apr 2015, 7:48 AM
Hello, I'm trying to add a simple validation for my grid cells. I'm doing something like this:

blur: function (field, event) {
if (field.value > field.maxValue || field.value < field.minValue) {
return false;
It works, but only when you click outside the grid. If you'll click on another cell, events will work like this: cell_1 - blur, cell_1 - focus, cell_2 - blur, cell_2 - focus. And in the end I'll loose focus from my invalid cell and it will be set on another cell, the same way if I just remove this logic.
Also a bit confusing, that if you set a breakpoint inside this listener, it will work. It will call cell_1 - blur, and skip any focus. Does anybody encountered such problem?

15 Apr 2015, 10:53 AM

I believe what you are experiencing here has to do with the timing in which the events are fired, especially since setting a breakpoint allows this to work as desired.

One option you could look into is setting a listener on the editor rather than on the field itself. Since you appear to be using built-in validation on the field (minValue and maxValue), you can utilize the canceledit event which is triggered when a change is cancelled or validation has failed.

Because this happens during a time in which the events are batched, you can set a global idle event that will fire once other events have finished and set focus back to the field with error.


Hope this helps,