Check existance of invalid cells before triggering the Ajax Logic

Tags: #<Tag:0x00007efc6acfe668>

Hello, I’m having difficulty in making a logic to check the existance of ‘invalid’ cells, before calling a Ajax program.

https://jsfiddle.net/3oygjwbz/1/

In the given sample, A2 cell is having an invalid value (the string ‘NG’ is put while the cell’s cellProperties.type is being NUMERIC.)
Thus it is causing a problem in G2 cell (calculation result is being #VALUE!).

In my sample, I placed the Save button, which ignites the Ajax logic to send the passed data to Server side logic (PHP).

Before igniting an Ajax call, is there any good way to detect ‘invalid’ cells in the spreadsheet, and when there is, stop to ignite the Ajax call?

I want to do something like the below code.

Do we have hot1.hasError() function?

// Save Button
Handsontable.dom.addEvent(btn_save, ‘click’, function() {

// do something here using AJAX

if (hot1.hasError()) {
// display error message to the system user, and do NOT allow to proceed to a Ajax call until the invalid cell gets fixed.
}
else {
// proceed to a Ajax call
}

});

Hey @kazuya.okamoto

the validateCells method will mark all invalid cells (red background + htInvalid className), so you can check if a cell has the class instance.getCellMeta(row, column).className = 'htInvalid' and then save the coordinates.

You can also check if the provided value (via afterChange hook) is a number and if not save the coordinates.

1 Like

Thanks for the information.

Getting coordinates of invalide cells is what I was imagining yesterday, too.
Now I’m glad to know that I could think like a Handson specialist like you.

I decided to just transfer the hot1.getData() array to Server Side logic (thru Ajax call),
and let the server side logic to validate the passed array in PHP.
Doing complicated coding in JavaScript is not my policy.

You can close this question.

To be honest, if you can do it server-side it’s even better as the performance on bigger tables really makes a difference.

1 Like