Skip to content

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

Closed

Description

@shadikhani

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.

Activity

  1. Legioth commented on Jun 17, 2019

    @Legioth
    Member

    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.

  2. shadikhani commented on Jun 17, 2019

    @shadikhani
    ContributorAuthor

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

  3. pekam commented on Jun 17, 2019

    @pekam
    Contributor

    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.

  4. Legioth commented on Jun 17, 2019

    @Legioth
    Member

    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").

  5. pekam commented on Jun 17, 2019

    @pekam
    Contributor

    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.

  6. jouni commented on Jun 17, 2019

    @jouni
    Member

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

  7. vursen commented on Jul 17, 2023

    @vursen
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions