FlowingCode/ChipFieldAddon

Validation pattern not working

Closed this issue · 1 comments

Setting a validation pattern with setValidationPattern(regex) does not work. Chips are displayed even if their label does not match the pattern

Vaadin Flow 12

Steps to reproduce:

ChipField<String> chf = new ChipField<>("Kzz");
chf.setAllowedPattern("[a-zA-Z]");
chf.setValidationErrorMessage("Some Error");
chf.setValidationPattern("[a-zA-Z]{2,6}");

Hi, sorry for taking so long to answer this.

Perhaps there is a misunderstanding related to setAllowedPattern() and setValidationPattern(). The first one lets you to specify a pattern that will control which characters can be entered into the input component. The second one shows a validation error (as a tooltip) if the pattern do not match.

Try with this:

        ChipField<String> chferror = new ChipField<>("Kzz");
        chferror.setAllowedPattern("[a-zA-Z0-9]+");
        chferror.setValidationErrorMessage("Some Error");
        chferror.setValidationPattern("[a-zA-Z]+");

In this case we are telling the component to prevent entering something that is not a alphabetical or number character. If a number is entered the error message as a tooltip will be shown.