You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Flow Binder article is quite outdated and includes examples that are nowadays incorrect. For example, it suggests adding an error message to EmailField using EmailValidator, whereas the correct approach is to use i18n instead. I propose reorganizing the article to start by explaining the default behavior and then gradually moving to more advanced customization options.
1. Component constraint validation and i18n error messages (default validator)
Begin by introducing the default behavior of component constraints and how i18n is used for configuring error messages:
EmailFieldemailField = newEmailField();
emailField.setI18n(newEmailFieldI18n()
.setPatternErrorMessage("This doesn't look like a valid email address"));
binder.forField(emailField).bind(Person::getEmail, Person::setEmail);
It might also be helpful to include an admonition explaining the difference with Vaadin 23 and mentioning that the previous behavior can be restored by disabling the default validator. Or, alternatively, the Vaadin 24 upgrading guide could be updated to cover this detail:
EmailField emailField = new EmailField();
+ emailField.setI18n(new EmailFieldI18n()+ .setPatternErrorMessage("This doesn't look like a valid email address"));
binder.forField(emailField)
- .withValidator(new EmailValidator(- "This doesn't look like a valid email address"))
.bind(Person::getEmail, Person::setEmail);
2. Defining custom rules on top of constraint validation (custom validators)
Next, explain how developers can add custom validation rules in addition to the default constraint validation:
EmailFieldemailField = newEmailField();
emailField.setI18n(newEmailFieldI18n()
.setPatternErrorMessage("This doesn't look like a valid email address")); // <---- defined using i18nbinder.forField(emailField)
.asRequired("Field is required") // <---- defined on the Binder
.withValidator(email - > email.endsWith("@acme.com"),
"Only acme.com email addresses are allowed")
.bind(Person::getEmail, Person::setEmail);
3. Opting out of default validator
Finally, explain how to disable the default constraint validation and define your own:
EmailFieldemailField = newEmailField();
binder.forField(emailField)
.withDefaultValidator(false)
.withValidator(newEmailValidator(
"This doesn't look like a valid email address"))
.withValidator(email - > email.endsWith("@acme.com"),
"Only acme.com email addresses are allowed")
.bind(Person::getEmail, Person::setEmail);
The text was updated successfully, but these errors were encountered:
The Flow Binder article is quite outdated and includes examples that are nowadays incorrect. For example, it suggests adding an error message to EmailField using EmailValidator, whereas the correct approach is to use i18n instead. I propose reorganizing the article to start by explaining the default behavior and then gradually moving to more advanced customization options.
1. Component constraint validation and i18n error messages (default validator)
Begin by introducing the default behavior of component constraints and how i18n is used for configuring error messages:
It might also be helpful to include an admonition explaining the difference with Vaadin 23 and mentioning that the previous behavior can be restored by disabling the default validator. Or, alternatively, the Vaadin 24 upgrading guide could be updated to cover this detail:
2. Defining custom rules on top of constraint validation (custom validators)
Next, explain how developers can add custom validation rules in addition to the default constraint validation:
3. Opting out of default validator
Finally, explain how to disable the default constraint validation and define your own:
The text was updated successfully, but these errors were encountered: