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

Binder ignores invalid value in DatePicker #1268

Closed
tepi opened this issue Apr 8, 2019 · 11 comments
Closed

Binder ignores invalid value in DatePicker #1268

tepi opened this issue Apr 8, 2019 · 11 comments

Comments

@tepi
Copy link
Contributor

tepi commented Apr 8, 2019

  • Description of the bug
    • DatePicker which is bound to a binder and has an invalid value entered by the user ends up with the binder status being valid.
  • Minimal reproducible example
Binder<Beanie> binder = new Binder<>();
binder.forField(dp).withConverter(new LocalDateToDateConverter())
		.bind(Beanie::getDate, Beanie::setDate);
binder.setBean(new Beanie("Normal"));
binder.setValidationStatusHandler(e -> {
	System.err.println("Status: " + e.isOk());
	e.getFieldValidationErrors()
			.forEach(err -> System.err.println("Error: " + err.getMessage().orElse("n/a")));
	e.getBeanValidationErrors().forEach(err -> System.err.println("Error: " + err.getErrorMessage()));
});
  • Expected behavior
    • When the user enters "foobar" into the DatePicker in the browser, the DatePicker is highlighted with red background which is expected. However when the binder's ValidationStatusHandler is triggered, the printouts in the code report that everything is ok and there are no errors.

Screen Shot 2019-04-08 at 10 56 33

  • Actual behavior
    • Binder validation should not pass since there clearly is an invalid value in the DatePicker.
  • Versions:
    • Vaadin / Flow version: 10.0.12
    • Java version: 1.8.0_121.jdk
    • OS version: macOS Sierra 10.12.6
    • Browser version: Version 73.0.3683.103 (Official Build) (64-bit)
@Legioth
Copy link
Member

Legioth commented Apr 8, 2019

I'm not sure what we can do about this, since technically, the value of that date field is null or whatever value it previously had. Binder doesn't know anything about the currently invalid value that is internal to the date field.

@tepi
Copy link
Contributor Author

tepi commented Apr 8, 2019

The component API does have a property named "invalid" that could be used. Or is there something preventing sending this property to the server?

At least it can't be left as it currently is. It's very confusing for the user and it also breaks forms where the save button is enabled based on validity.

@denis-anisimov denis-anisimov transferred this issue from vaadin/flow Nov 15, 2019
@denis-anisimov
Copy link

As I understand the server side never knows about foobar value on the client side since it's never sent to the server side.
So from the server side there is nothing to validate.
Some validation happens on the clients side and it always clashes with the server side validation.
Something should be done either in the client side component or in the server side integration (but anyway this is specific for date picker).

@fabst2w
Copy link

fabst2w commented Jan 3, 2020

@Legioth: It could be a solution to enforce a regular expression at client side.

com.vaadin.flow.component.textfield.TextField offers a method setPattern and with a pattern set the client side avoids typing in invalid characters. That works fine.

Couldn't you set a pattern like "\d{1,2}.\d{1,2}.\d{2,4}" at the DatePicker? Ideally (and in my case a must-have) depending on the locale.

@Legioth
Copy link
Member

Legioth commented Jan 7, 2020

Now when I come to think of it, this is already fixed in Vaadin 8 with the "default validator" concept which allows the field component to provide its own custom validator logic that is automatically used by Binder.

@guttormvik
Copy link

For reference: We have the same issue with ComboBox: Write an incorrect value and tab out, and the value is reset. https://github.com/vaadin/vaadin-combo-box/issues/864

For ComboBox there is special support for allowing invalid values, which can be used as a workaround, but maybe ComboBox, DatePicker and other fields should have a unified approach to invalid values? From my point of view I want all state to be available on the server-side, so I wouldn't mind all textfield components also having access to the textfield value. Valid or not.

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-date-picker-flow Oct 6, 2020
@mvysny
Copy link
Member

mvysny commented Nov 13, 2020

Miki is fixing a similar issue in his SuperFields add-on, here: vaadin-miki/super-fields#241 . Even though the issue relates to BigDecimalField, the fix should also affect DatePicker. After the fix is released, please try using the SuperDatePicker.

@ssmith-agristats
Copy link

Would appreciate a fix for this issue. Thanks.

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-date-picker May 19, 2021
@vaadin-bot vaadin-bot transferred this issue from vaadin/web-components May 21, 2021
@nittka
Copy link

nittka commented Aug 26, 2021

see also #1158 and #1778

@vursen
Copy link
Contributor

vursen commented Sep 5, 2022

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 vaadin-featureflags.properties:

com.vaadin.experimental.enforceFieldValidation=true

Any feedback would be highly appreciated. For more details, please refer to vaadin/platform#3066.

@vursen
Copy link
Contributor

vursen commented Jun 14, 2023

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.

@vursen vursen closed this as completed Jun 14, 2023
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