How to validate a cell is required/mandatory on load and on Save?

Tags: #<Tag:0x00007fd2c20fb530>

Hi,

We are using HandsonTable with Angular. and
We are getting cell settings from external json, like below.

{
“columns”:
[
{
“name”:“test”,
“age”:“23”
},
{
“name”:“test”,
“age”:“23”
}
],
settings:[
“name”:{
“type”:string,
“isRequired”:true,
“length”:30
},
“age”:{
“type”:numeric,
“isRequired”:true,
}
]
}

From the above seetings, we are try to validate our cells on load and on save.

Now, we need to validate the cells is required/mandatory on load and save also…

is beforeCellValidate hook is right place to write those validation?

or do we need to write custom renderer method?

Kindly suggest,

If any sample code is available, Please provide those samples.

Thank you
Prabu Kuppusamy

Hi

a custom validator should do the job and before saving you can call the validateCells method.

Here https://handsontable.com/blog/articles/2018/10/advanced-data-validation-in-handsontable is a blog post with examples of code that should help you to acheive the goal.

Hi… I have went through the give sample code, I think, I’m having different scenario.

What if this ‘data: ‘discount_available’,’ column we are not using, so this method won’t help ‘this.instance.getDataAtRowProp(this.row, ‘discount_available’)’ , am i correct?

So, From my sample data, I can mark name column only mandatory, not age column, How can I achieve this? Kindly suggest me.

Since I cannot create column like this ‘name_required, age_required’

I Hope you understood my scenario.

If you need to have data in a column (it is mandatory) you should use the allowEmpty: false. Have you already tried it?

Hi… I have tried the allowEmpty in our hottable, seems not working,
and I have tried with few examples from jsfiddle, there also not working.

I have tried with below one.

https://jsfiddle.net/api/post/library/pure/

hotSettings: Handsontable.GridSettings = {
startRows: 5,
columns: [
{
editor: CustomEditor,
allowEmpty: false
}
],
colHeaders: true,
colWidths: 200
};
}
So, On the load the cells should be in (Red) Invalid cells, Am i correct? Seems not working.

Kindly mention, How to use allowEmpty and Please provide any samples in jsfiddle/stackblitz if you have.

Thank you
Prabu Kuppusamy

Can you update the example? The link is broken and the settings printed in the post are missing the editor logic and data.

I took that jsfiddle url from this example page.

https://handsontable.com/docs/7.2.0/frameworks-wrapper-for-angular-custom-editor-example.html

if this link is also not working… Kindly provide any other example which is used the allowEmpty.

Regards,
Prabu Kuppusamy