vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
618 stars 167 forks source link

Binder.setAsRequiredEnabled instantly validates the field #17515

Closed felix-office closed 9 months ago

felix-office commented 1 year ago

Description of the bug

Using setAsRequiredEnabled instantly validates the bound field. As this leads to a pretty bad UX/UI this is a bug for me.

I have a checkbox. When the checkbox is checked, a text field is visible, which in this case is required. When the checkbox is unchecked, the text field is no longer required, so the asRequired state must be changed. Otherwise the form will be invalid on a hidden text field. I'm using setAsRequiredEnabled, which means that when the checkbox is checked, the text field is immediately invalid and red.

As the user hasn't even had a chance to enter anything, this is bad UX. I don't see why the validation has to be immediate.

Workaround: Adding and removing the whole binder.

Expected behavior

Validation is not performed immediately.

Minimal reproducible example

I won't provide an reproducible example here as you can see it directly in the source code: https://github.com/vaadin/flow/blob/49d68c756df67e25ff125d838f45cba6a073d7f7/flow-data/src/main/java/com/vaadin/flow/data/binder/Binder.java#L1530-L1541

Versions

Vaadin: 24.1.2 Flow: 24.1.3 Java: Amazon.com Inc. 17.0.8.1 OS: amd64 Linux 6.2.0-26-generic Browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Live reload: Java active (Spring Boot Devtools): Front end active

vaadin-bot commented 9 months ago

This ticket/PR has been released with Vaadin 24.3.4.