Custom multi message validate at validator

Tags: #<Tag:0x00007f45280e6db0>

I have a column (Text type) that need to validate not null, must be follow string format, at least 5 character
I want custom 3 message for them, I know I can custom message on afterValidate, but can not trigger afterValidate as text type. If I regist function at validator, I can not custom message.
So, What is the best way, like just set validator = true, then I can trigger afterValidate. Or custom message at validator function and how can I do that ?

Hi @TonyNguyen

your custom validator should validate the cells (have a true/false condition to follow). Then based on the true/false response you can work with the result in the afterValidate hook.

Hi @aleksandra_budnik.
Example I have 3 message depend on the error:

  • Not null: " You must be enter"
  • Max length: “The maximum is 5 character”
  • Format: “Format incorrect, value must be ABC_XXX”
    How can I set the message at afterValidate when validator only return true/false. Or I have to validate twice, at validator then afterValidate to set the message ?

Handsontable provides the ability to request a value out-of-the-box by the allowEmpty option. You can check it here

The editor can limit the number of chars so you can do that before the validation.

When it comes to the formatting you should consider allowing / disallowing to type a value if it’s invalid by the use of and then use a proper regex value to request the ABC_XXX format.

My purpose is how can I display the message depend on validate check

  • Check format: “Format incorrect, value must be ABC_XXX”
  • Check duplicate: " Value can not be duplicated"
  • And some validate check more depend on my business.

Hi @TonyNguyen

as mentioned the format should be handled by the regex. Here you have some examples on how to create one for your needs.

When it comes to duplicates you would need co create a custom logic. We do not have any examples on handling duplicated values in a column. In the theory, however, you can usethe afterChange hook to check if the new value is already in the array of instance.getDataAtCol() and if it is it means that the new value duplicates other value in the column.