Validator Issue

Hi All,
Is there any way to remove validator from Cell. I am having below scenario;

  1. I will edits / enters data to cell.
  2. After that i am having one button to validate all cell, if handsonTable contains error i need to show alert message with error count. After that i need to remove validator.

I am able to add validator with below code;

hot.updateSettings({
cells: function (row, col, prop) {
var cellProperties = this;

		if(col == 0){
			cellProperties.allowInvalid = true;
			cellProperties.invalidCellClassName = "errorCell";
			cellProperties.validator = customValidator;
        }
		return cellProperties;
	}
});

Hi @achyutanand

some cell types have their own predefined validator. If you do not want any you can use the text cell type (it doesn’t have a validator) or pick any other cell and pass validator: null in cell settings.

Hi @aleksandra_budnik, thanks for quick reply,
But as per my requirement can i do follow stuff;

For adding validator in run-time;
hot.updateSettings({
cells: function (row, col, prop) {
var cellProperties = this;

		if(col == index){
			cellProperties.allowInvalid = true;
			cellProperties.invalidCellClassName = "errorCell";
			cellProperties.validator = customValidator;
        }
		return cellProperties;
	}

});
After validate, i want to remove the validator from Cell.
hot.updateSettings({
cells: function (row, col, prop) {
var cellProperties = this;

		if(col == index){
			cellProperties.allowInvalid = true;
			cellProperties.invalidCellClassName = "errorCell";
			cellProperties.validator = null;
        }
		return cellProperties;
	}

});

I don’t want to pass type attribute while initializing handsontable obj.

Sure, if it works in your project I do not see any problems that this code can produce.

But this solution is not working properly, can you help me, how to remove validator in Cell run-time (Runtime means; outside of handsontable i have two buttons where i can add validator and remove validator).

Maybe you mean something like this http://jsfiddle.net/s7fycx2e/ ?

Yes @aleksandra_budnik. Thanks for help. Just have one clarification, Can we maintain same stage for all cell (“Red BG”) after switching validation off.

Here is the scenario;

  1. Switch on the validator
  2. Enter some Alpha character.
  3. After entering value cell will become “Red” (Error Cell)
  4. Switch off validator

Issue is after switch off validator i am loosing “Red color highlighted” cell. Can we keep all error cell in same stage?

If you would like to keep the background I think that you should add an additional class if cells did not pass the validation as the cell loses the background as it doesn’t have the validator after setting it off. Can you tell me why you would like to switch off the validator if you want to have the red background?

I have added cellProperties.invalidCellClassName = “errorCell”; properties also but after switching off i am loosing cell style.

My requirement is; I will have more than 1000 rows data and one time (have external button) i will do all validations through ajax, after that i want to switch off the validator. (Means onchange/ontab out i shouldn’t do any validation)

this class relates to an invalid cell and cell is not invalid where there is no validator. You would need to add an additional class via cell metadata in afterValidate or an afterChange hook.

Thanks lot @aleksandra_budnik. I have achieved my requirement.:slight_smile:

You’re welcome @achyutanand

I think that we can close the issue now.