-
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
Entering invalid value to DatePicker does not show DatePicker as invalid in browser #1158
Comments
Requires complex changes both on the components and flow counterparts logic as well as to the flow Binder behavior: https://github.com/vaadin/components-team-tasks/issues/489 |
More info in epic in https://github.com/vaadin/components-team-tasks/issues/528 |
Could be fixed by synchronizing the This isn't related to Binder necessarily. Like other component validators, this will not work with Binder before |
The validation at Java side has so far been a function of the server-side value, executed on There is no 1-to-1 relationship between the server-side value and So there are two problems to solve:
Also, we should keep in mind that similar fix migh be needed for other components (at least Syncing the
|
- sync input value from client to server - use input value in server-side validation - validate on blur in addition to value change event fix #223
- sync input value from client to server - use input value in server-side validation - validate on blur in addition to value change event fix #223
After releasing a web component fix that blocks this, I'll open a fixing PR for DatePicker (adding the logic to component-level validation). After this change, the component should validate correctly when NOT using Binder. To validate correctly in all cases including Binder, two more steps are needed:
If/when the upcoming DatePicker PR is released, but neither of the above-mentioned steps are, the following problems will occur when using Binder:
If/when step 1 is implemented and step 2 not, the following problem will occur when using Binder:
To avoid introducing a regression, and to make this fix and the existing component-level validation work with Binder, I'd vote for releasing all of these changes in the same platform version. Since step 2 needs a minor bump, this would mean postponing the fix until Vaadin 14.3. |
including a fix that is blocking https://github.com/vaadin/vaadin-date-picker-flow/issues/223
including a fix that is blocking https://github.com/vaadin/vaadin-date-picker-flow/issues/223
- sync input value from client to server - use input value in server-side validation - validate on blur in addition to value change event fix #223
Blocked by vaadin/flow#8242 Here's a branch with the changes excluding the implementation of the not-yet-existing event: https://github.com/vaadin/vaadin-date-picker-flow/tree/invalid-date-string-fix |
#1778 duplicates this issue |
Will this be available as a (what I think) necessary feature in LTS version 23 ? |
I'm using this workaround to fix the issue: val datePicker = DatePicker()
datePicker.element.executeJs(
"""
this.addEventListener("blur", event => {
if (this.value == '' && this.$.input.inputElement.value != '') {
this.$.input.inputElement.value = ''
}
})
"""
)
The value of the field is cleared when it is invalid. |
Thanks for sharing the snippet. It gives feedback to the user - indicating that something is wrong, but it is not perfect from a user experience perspective: "I entered a value and it is gone..." The latest date picker version supports custom date formats (primary format is displayed, others are used for alternative parsing) which solves one of our problems (user enters date in other format). THANKS!!
For required date fields, this is OK. A date can be entered in different formats (e.g. copy/paste). If there are format problems the date value is null, the text is still visible and the field is marked as having an error. I still consider this a major bug in a fundamental component and hope for a fix. |
@nittka You are right, my workaround doesn't provide a good UX. |
No, we wrote our own (java) component, a layout containing textfield and (default) picker, adapting the styling so that the picker's input field is not shown. |
#13940) (CP: 23.1) (#13993) Adds the needed API to notify Binder about validation status changes that happen in field components. Fixes #8242 Related to vaadin/flow-components#1158
FYI: We have just introduced new validation behavior that is supposed to solve many different validation issues that people were complaining about, including this one. The new behavior is available under the feature flag in v23.2 for several components including DatePicker. To enable the feature flag in your application, add the following to
Any feedback would be highly appreciated. For more details, please refer to vaadin/platform#3066. |
I would say it works partially or I haven't quite figured out how it's supposed to work yet. If I use a Binder and a DatePicker and simply set an object via setBean(...), the field becomes invalid as soon as I enter an invalid value. However, nothing is written to the model - I would have expected null to be written to the model. When I then call validate on the binder, it reports OK. If I enter a different value afterwards, the field remains invalid. However, I don't use a binder in my framework, so it's quite possible that I used it incorrectly in my little test. Without a binder (in my framework), I can register a ClientValidatedEventListener (addClientValidatedEventListener). This is correctly notified with the feature switch enabled when an invalid value is entered in the UI. (I write null in my model in this case.) However, if I subsequently change the value back to the last valid value, I don't get an event and the field remains invalid. For example: I enter "01/01/2022". I then enter "a01/01/2022" (field becomes invalid). Then I correct the value and remove the 'a', the field remains invalid and I get no event on the server. I would expect the internal value of the field to be set to null as soon as an invalid entry is made. The incorrectly entered text should remain, otherwise the user will not be able to understand their mistake. However, the field should not simply assume that the last valid value is still the current value. |
Yes, that's how it should work and that's actually how it works for me (see the example below). I tried it both with a binder and without. I wonder what I'm missing 🤔 Screen.Recording.2022-10-05.at.17.02.22.mov@Route(value = "date-picker")
public class DatePickerView extends Div {
public DatePickerView() {
Div value = new Div();
DatePicker datePicker = new DatePicker();
datePicker.addValueChangeListener(event -> {
value.setText("Value: " + datePicker.getValue());
});
add(datePicker, value);
}
} P.S When I type in |
Okay, that's weird. The difference:
I hate that the picker always opens when I tab through my application, so I always set auto open to false. If I remove this line, it works. Please tell me how auto open correlates with validation behavior. |
That’s not how it is supposed to work. “Auto open” should only affect “click to focus”, not “tab to focus”. Typing a value to the field does open the popup, though. I assume that’s what you mean, that you tab through the app and type values to the fields. |
Ok, that's right. Maybe it was different in earlier versions (10 or 14). But it remains annoying, because after entering a date I can't just tab to the next field but have to confirm the date with enter first. But apart from that, I don't understand why the field behaves differently when I disable auto-open. This is still a bug, isn't it? |
Is it possible that the bug will be fixed? I would like to use the validation but leave auto-open at false. |
Hey @cdir! Thank you for your report. We have fixed this bug. Please, follow V24.0.0.alpha6 which will be out soon. |
We definitely need a fix in Vaadin 23! |
@cdir I apologize for the confusion. It is already available there. Please, check out V23.3.0.beta2 |
@vursen I just tried vaadin 23.3. Unfortunately I still only get an error when autoOpen=true is set. |
What kind of error do you get? Is it the same problem? Or is it different now? |
I get no error. There is just no value change event when autoOpen=false while it is triggered with autoOpen=true. So, no different behavior. |
@vursen sorry for the confusion. I found the problem, there was a version mismatch in my sample. Now it works as expected. Thank you very much. |
I'm glad it worked out. Thank you for testing it. |
The new feature flag solves this problem but adds another: My situation:
|
The issue has been resolved by the new validation mechanism which is enabled by default in Vaadin 24. For any further bugs, please create separate issues. |
To reproduce the issue:
Additionally, there is no easy way to validate invalid input from Java side and set the DatePicker into invalid mode.
The text was updated successfully, but these errors were encountered: