not working as expected

Hi all! I have the following code:
emailField = new EmailField(); emailField.setLabel("Email"); emailField.setRequired(true); binder .forField(emailField) .asRequired("Please enter an email.") .withValidator(new EmailValidator("Incorrect email.", false)) .bind(Data::getEmail, Data::setEmail);
When I run the application and enter an invalid value in this field, I expect the message “Incorrect email.” to be displayed below it. But this doesn’t happen - the field is displayed in red, but the message is not shown. Can anyone explain if I did something wrong or is this a bug?

When are you expecting the error (on blur / while typing) to be shown and what did you type into the field? Version?

Edit: assumption: you are using 24+ and this could be a regression because of the client side validation… to fix that use a TextField instead of a EmailField - with your binding validations in place it would be just redundant anyway

Yes, changing EmailField to TextField helped, the error is now displayed, thanks! But still, it’s strange and not obvious…

Yeah… pinging @useful-whale as PO :wink:

Reasoning behind this behavior: Email field has client side validation that are also run on the server as first in the binder chain (pattern if it’s a correct mail) - but without the possibility to define an error message (“feature request” is open / or showing one, making the validation in the chain not called because the first one already failed

Friend, you help me figure out the problem not for the first time, thank you for that. I see you are very knowledgeable about Vaadin. Could you also tell me when I should use field.setRequired(true) or field.setPattern(…) and when should I use binder.asRequired() or binder.withValidator(new RegexpValidator(…)). I can’t figure out what the fundamental difference is and whether it makes sense to duplicate the checks by calling both field.setRequired(true) and binder.asRequired()…

Personal opinion: always use the methods on the binder, there is no need to duplicate them on the fields. You have way better customizing possibilities based on the binder. Only time I go with field based validations is in really simple forms with e.g. a single field like a search field.

Got it, thanks a lot! :slightly_smiling_face:

Unless I’m mistaken, the message set via emailField.setErrorMessage(String) should work in that situation.