-
Notifications
You must be signed in to change notification settings - Fork 66
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
Server-side date parsing #2466
Comments
Flow has public void setFallbackParser(Converter<String, LocalDate> fallbackParser); Edit: V8 had a similar handling with |
Cherry-pick of: vaadin#2409 Fixes vaadin#2466 Fixes vaadin#2319 Co-authored-by: Sascha Ißbrücker <[email protected]> Co-authored-by: Sascha Ißbrücker <[email protected]> (cherry picked from commit 56c878a) Co-authored-by: Tatu Lund <[email protected]>
Here I described how this feature could potentially be implemented after the validation refactor is done. |
We are considering going with Rolf's original API design where the parser returns either a datePicker.setI18n(new DatePickerI18n()
.setBadInputErrorMessage("Invalid date format")); // Will be displayed if the parser returns `null`
datePicker.setFallbackParser(s -> {
if (s.equals("tomorrow")) {
return LocalDate.now().plusDays(1);
} else {
return null;
} The reasoning behind not adding error message support to the parser now is that there are already two existing approaches: i18n and setErrorMessage(). Adding a third approach seems likely to make the error handling mechanism harder to understand. That said, even without direct support, it will still be possible to display different error messages based on the parser logic using this workaround: datePicker.setFallbackParser(s -> {
if (s.equals("tomorrow")) {
return LocalDate.now().plusDays(1);
} else if (s.equals("tomo")) {
datePicker.getI18n().setBadInputErrorMessage("Must be tomorrow");
return null;
} else {
datePicker.getI18n().setBadInputErrorMessage("Invalid date format");
return null;
}
} If you have a different view, please feel free to share your perspective and a use case. |
While I agree that "yet" another error handling mechanism is harder to understand - the mentioned "another" error handling mechanismn is the standard mechanism to be used in every flow project when you use validator or converter with Binder where the result ( @simasch I think we talked about this feature in the past.. you might be interested in this as well Edit: If it's a technical limitation.. or it would make it easier for you to handle it.. I would propose the following: add |
I share @knoobie opinion. The fallback parser should not set the error message directly but return the error message or a date. |
Describe your motivation
Some applications use various specialized strings for quickly entering dates, such as
+1
ortomorrow
for tomorrow. While we can extend the parsing formats supported by Date Picker via date-fns in the future, it is likely that there will always be custom, application-specific strings that even date-fns does not support. Providing a solution for server-side parsing of dates, that allow developers to provide their own parsing, would solve these use cases.Describe the solution you'd like
A way to provide server-side date parsing as a fallback (if the parsing formats provided are unable to parse the entered string). The API could be something along the lines of
The text was updated successfully, but these errors were encountered: