Multiple table validation on submit

Tags: #<Tag:0x00007efc655b4ee8>

Hi,
I am facing an issue with multiple table validation on a page.
I am using multiple handsontable instances for a form and I want to validate them on submit.

I currently cycle through each table on the page and call the validateCells() method, but it seems like the callback is asynchronous and thus I am not able to wait for every table to be validated before the function progresses; but since it is not a promise, I can’t await it.

Please see the JSFiddle attached for the reproduction of my issue and further explanation.
https://jsfiddle.net/4khx0ojc/1/

Is there a way I can solve this problem?
Thanks in advance for your time.

That is correct. However, you can run the needed logic in the afterValidate hook. It runs when al the cells are validated.

How so? I could of course attach a Hook, but I would still have the problem of making sure the tables are validated when I want them to.

If I rely on automatic validation, a user can simply submit the form before touching any of the fields in a table and it will result as valid.

So as far as I can tell, the problem of waiting for the validation to end persists.

Hi @makimaj242,

We use setImmediate to solve validators’ functions. The browser will invoke the validateCells’ callback out of the main thread.
Source: https://github.com/handsontable/handsontable/blob/d78f7d062c2613994b405fdbe3dd83f3433b6d89/src/core.js#L1281

I modified your demo a little bit: https://jsfiddle.net/swistach/fqhyc18x/.

I followed what you had in the example, so I used callbacks that later I put in a simple queue to detect the end of validation.

Of course, you can simplify it using async/await or promises.