Hi, I have nuanced issue, with a hopefully simple solution I would like to get some help with. Let me start with some context:
We have a setup where we track changes to our grid rows, and we save the changes once the user leaves the current row. This can either happen by moving selection to the next row or, more importantly for my question, when the user clicks outside of handsontable.
We use afterChange
hook to keep track of all the interesting changes, and afterDeselect
hook to trigger the save call, and this has worked well for a long time.
Recently, we started incorporating validation and found that one of the consequences of declaring a validator
for a particular cell type is that saving the cell becomes an asynchronous operation. This presents a problem for us because it changes the order in which afterDeselect
and afterChange
events are triggered - in application terms our trigger to save the changes comes before the application learns the changes have happened at all.
I’ve done some exploring in HoT codebase and came up with a workaround that seems to work: If there is an activeEditor
present, I subscribe to postAfterValidate
event and trigger the save call from within the callback. Otherwise I keep the old behaviour. This seems to work but discussing with the team, we are uncomfortable leaving this code in because it relies on an undocumented event (namely postAfterValidate
).
Finally, I can ask my question: Do you have a recommended way to achieve saving the changes consistently after deselect, regardless of whether there is a cell currently being edited or not? Ideally, we want to only do it if the currently edited cell is valid at the moment (think allowInvalid
prop is false
).
If the answer is no, can you please add the postAfterValidate
event (hook) to documentation so we have some confidence it is there to stay? Alternatively could you expose a completely new (but documented) event triggered around the same time as postAfterValidate
?
Thanks,
Sandi