Issues with providing a custom validator

Tags: #<Tag:0x00007f0b0b589d88>

Hi,

I’m having issues with implementing a custom cellType that accepts a number or a value from the dropdown.

This main stems from the fact that wrapping a provided validator (in this case Handsontable.validators.DropdownValidator) leads to different behavior.

https://jsfiddle.net/neo3fwvy/

Shown in the fiddle, if you type an invalid string such as ‘asd’ into the Normal Dropdown Column, the cell shows up as invalid which is intended behavior.

In the second column, I have simply wrapped DropdownValidator in a function and suddenly ‘asd’ is now accepted as a valid value.

Why is this the case?

Thank you for sharing the example. I will look into it and share my thoughts as soon as possible.

Hi @coffeeshot123

I have a demo https://jsfiddle.net/5k9Lxbup/

Please check if it meets your requirements. I have added the line 34 and now it accepts the same values as the first column (only values from its own source list)

Hi @aleksandra_budnik,

Thanks for the reply. I don’t think the jsfiddle fixes the issue as the wrapper function actually isn’t being called in your fiddle.

If you see my update below (actually added the wrapper function to the cellType registration on line 22), the issue still persists.

https://jsfiddle.net/5k9Lxbup/9/

You’re right @coffeeshot123

I have tried to call the validateCells() after the cell is field with invalid data (as I thought that the reference needs some time to recalculate) but it did not help. I will investigate it and let you know about the results.

I have asked our developer to take a look at the example and be back with reply as soon as possible.

Thank you! I really appreciate it.

Hi @coffeeshot123

I got a message back from the developer:

DropdownValidatorWrapper needs to return function which applies Handsontable.validators.AutocompleteValidator.

Additionally, the validator needs to call DropdownValidatorWrapper function

https://jsfiddle.net/rgm3htx2/

Thanks for the reply @aleksandra_budnik!

This works well.

I just want to point out that the behavior still isn’t consistent because if you type ‘asd’ in the first dropdown and don’t click enter, all the options still display in the dropdown. For the custom validator, the values in the dropdown are filtered and there are no values there.

EDIT: I figured out that I needed to add filter: false to avoid filtering.