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

asRequired method with Binder does not work properly with the tab button #1232

Closed
shadikhani opened this issue Jun 14, 2019 · 7 comments
Closed

Comments

@shadikhani
Copy link
Contributor

When I use the code below and I use the tab button only to tab between components, the asRequired method in binding does not work properly.

Person person = new Person();
Binder<Person> binder = new Binder<>();
binder.setBean(person);
TextField textField = new TextField("Name");
binder.forField(textField)
        .asRequired("Please enter your name")
        .bind(Person::getName,
                Person::setName);

First Demo:

FirstDemo
Second Demo:

SecondDemo

In the FirstDemo.gif when you click on the name field and enter a data and you delete it and you use your tab to go to another component the requirement is not checked.

In the secondDemo.gif when you click on the name field and enter some data and use your mouse to click somewhere out of that text-field area and then select the data and delete it the requirement validation will work.

@Legioth
Copy link
Member

Legioth commented Jun 17, 2019

My guess is that this is related to the logic that avoids eagerly showing validation errors for untouched fields. This logic is in place to avoid situations where a newly opened (empty) form form would look scary by being full of validation error indicators.

Most likely, the server-side validation logic doesn't get out of this mode for the field until a value has been submitted to the server, which might not happen if you type something in there and remove it again before tabbing out. From the server's point of view, this is the same situation as if you'd just tab through the fields without making any changes to them.

@shadikhani
Copy link
Contributor Author

shadikhani commented Jun 17, 2019

When I use this line of code it works properly:
textField.addBlurListener(event -> binder.validate());

@pekam
Copy link
Contributor

pekam commented Jun 17, 2019

The basic difference between the web component and Flow is that the web component runs validation on blur event and Binder does it on ValueChangeEvent.

This causes differences in the behavior depending on the ValueChangeMode. With the default mode, ValueChangeEvent is not fired at all in the described case, since the value hasn't changed, so validation is not triggered. When using ValueChangeMode.EAGER, Binder runs validation on every keypress which is also different from the web component.

@Legioth
Copy link
Member

Legioth commented Jun 17, 2019

Yeah, that validates my hypothesis. The question is still whether it's desirable from a UX perspective that an initially empty field would show up as invalid after you've tabbed through it but not made any changes (or made changes that have been reverted "immediately").

@pekam
Copy link
Contributor

pekam commented Jun 17, 2019

The question is still whether it's desirable from a UX perspective that an initially empty field would show up as invalid after you've tabbed through it but not made any changes (or made changes that have been reverted "immediately").

This is how our web components work, and I'd assume the UX has been designed thoroughly during their implementation.

@jouni
Copy link
Member

jouni commented Jun 17, 2019

Yes, tabbing through a field has been considered “enough” to trigger the validation.

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-text-field-flow Oct 6, 2020
@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-text-field May 19, 2021
@vaadin-bot vaadin-bot transferred this issue from vaadin/web-components May 21, 2021
@vursen
Copy link
Contributor

vursen commented Jul 17, 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 new issues.

@vursen vursen closed this as completed Jul 17, 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

7 participants