Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype API for setting error messages through i18n and overloads [3 days] #6280

Closed
vursen opened this issue May 8, 2024 · 3 comments
Closed
Assignees

Comments

@vursen
Copy link
Contributor

vursen commented May 8, 2024

Let's prototype API for setting error messages through i18n and overloads. Below are some examples of how it's supposed to look like.

Example 1 (setting error message through i18n objects):

datePicker.setMin(minDate);
datePicker.getI18n().setBadInputErrorMessage("Date has incorrect format");
datePicker.getI18n().getBadInputErrorMessage();
datePicker.getI18n().setMinErrorMessage("Date must be later than " + minDate);
datePicker.getI18n().getMinErrorMessage();

Example 2 (setting error messages through constraint method overloads) see #6280 (comment)

// These are just aliases for the corresponding i18n methods.
datePicker.setMin(minDate, "Date must be earlier than " + minDate);
datePicker.setMax(maxDate, "Date must be later than " + maxDate);

Example 3 (cross-field validation with Binder):

datePicker.setMin(minDate);
datePicker.getI18n().setBadInputErrorMessage("Date has incorrect format");
datePicker.getI18n().setMinErrorMessage("Date must be later than " + minDate);

binder.forField(datePicker)
        // Disable the default validator
	.withDefaultValidator(false)
        // Add a custom validator
	.withValidator(dateOrAnotherFieldPredicate, "You must fill either one field or another") 
        // Add the default validator manually. It will use error messages from the i18n object
	.withValidator(datePicker.getDefaultValidator()) 

Additional context

@vursen vursen changed the title Prototype API for setting error messages through i18n and overloads Prototype API for setting error messages through i18n and overloads [3 days] May 8, 2024
@vursen vursen self-assigned this May 8, 2024
@knoobie
Copy link
Contributor

knoobie commented May 8, 2024

I personally would love to have the option to have setMin(LocalDate min, ErrorMessageProvider errorMessageProvider) instead of the i18n object for full flexibility. https://vaadin.com/api/platform/current/com/vaadin/flow/data/binder/ErrorMessageProvider.html

@vursen
Copy link
Contributor Author

vursen commented May 20, 2024

I personally would love to have the option to have setMin(LocalDate min, ErrorMessageProvider errorMessageProvider) instead of the i18n object for full flexibility.

After some prototyping, we decided to postpone introducing constraint method overloads. Implementing them now through i18n would require a breaking change later to support ErrorMessageProvider. We plan to revisit this when the Flow components fully integrate with the new i18n mechanism to explore other alternatives.

@vursen vursen closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants