I can't stop event propagation from the editCellEnding event. In the event a user enters something other than a number, I show them an alert and want the focus to remain on the current cell, and it to stay in edit mode. If I try this and enter an invalid value and tab away, then the alert is shown but the focus is moved to the next cell and it enters edit mode. I've tried stopPropagation, stopImmediatePropagation, preventDefault and just returning false but nothing seems to stop it.
editCellEnding: function (evt, ui) { if(ui.value!='' && isNaN(ui.value)){ alert('Not a valid scoring number'); evt.stopPropagation(); evt.stopImmediatePropagation(); evt.preventDefault(); return false; }
Hi Chris,It seems to me that the checks you are performing are not sufficient to capture the fact that if the cell is left empty, its actual value is NULL.Also, if you're editing a number-valued column, our igNumericEditor ensures that the user can enter only numbers (no funny business).Thus, here's the code I can suggest:
editCellEnding: function (evt, ui) { if(ui.value === "" || !ui.value) { alert('Not a valid scoring number'); evt.stopPropagation(); evt.stopImmediatePropagation(); evt.preventDefault(); return false; } return true; },
PS: Check are based on the suggested answers from SO (http://stackoverflow.com/questions/154059/what-is-the-best-way-to-check-for-an-empty-string-in-javascript)
That was just code to try to get the event to stop and focus to remain in the current cell. The values can be an empty string (the default that was coming from the json data or a number the user entered - which is why I was checking and allowing either an empty string (if the user entered edit and left without changing anything) or a false from isNaN. Thanks for the info on the igNumericEditor though.
The code was being executed and going all the way to the return false statement (having tried each of the previous statements by themselves and together as well) but the propagation didn't stop and the focus was moved to the next cell as a result of the tabbing/hitting enter/etc...
How can I stop the event from continuing and keep the focus in the current cell?