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

EmailField showing invalid when empty and not required #5361

Open
drewharvey opened this issue Aug 8, 2023 · 4 comments
Open

EmailField showing invalid when empty and not required #5361

drewharvey opened this issue Aug 8, 2023 · 4 comments

Comments

@drewharvey
Copy link

Description of the bug

Vaadin 23.3.19 with enforceFieldValidation=true

EmailField will be marked as invalid if you enter text and then clear the text. It will only show as valid if you enter an email.

emailbug

Repro steps:

  • Enter text into email field and blur
  • Clear text from email field and blur
  • Expected: field shown as valid and empty
  • Actual: field shown as invalid and empty

Expected behavior

Field should be valid if empty.

Minimal reproducible example

var email = new EmailField("Email");
add(email);

Versions

  • Vaadin / Flow version: 23.3.19
    com.vaadin.experimental.enforceFieldValidation=true
@drewharvey
Copy link
Author

Seems like the binder validation is not working correctly with the flag on. Consider the following code with simple binding.

var email = new EmailField("Email");
add(email);

var binder = new Binder<Person>();
binder.forField(email)
        .withValidator(new EmailValidator("Invalid email address", true))
        .bind(Person::getName, Person::setName);
binder.setBean(new Person());

Without enforceFieldValidation
email-without-flag

With enforceFieldValidation
email-with-flag

@caalador caalador transferred this issue from vaadin/flow Aug 15, 2023
@yuriy-fix yuriy-fix assigned vursen and unassigned vursen Aug 16, 2023
@drewharvey
Copy link
Author

In case anyone needs a workaround, you can override the isFeatureFlagEnabled method and force the field to behave as if the ENFORCE_FIELD_VALIDATION flag is false.

var field = new EmailField("Email") {
    @Override
    public boolean isFeatureFlagEnabled(Feature feature) {
        if (feature == FeatureFlags.ENFORCE_FIELD_VALIDATION)
            return false;
        return super.isFeatureFlagEnabled(feature);
    }
};

@drewharvey
Copy link
Author

Seems all custom validators do not run until a valid email formatted string is entered. You can see in the GIF posted above that when using enforceFieldValidation the EmailValidator does not trigger.

@vursen
Copy link
Contributor

vursen commented Sep 19, 2023

Seems all custom validators do not run until a valid email formatted string is entered.

Right, it's because Binder first runs the default validator provided by the component. And the email validation is part of the default validator. The problem is that there is currently no way to provide error messages for errors resulting from the default validator. This is why the field appears red without any error message. It's a known problem. Please, refer to #4618 for further updates.

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

3 participants