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] Permanent invalid state with optional (text based) fields #2341

Open
Feuerwerk opened this issue Apr 18, 2024 · 0 comments
Open

[Binder] Permanent invalid state with optional (text based) fields #2341

Feuerwerk opened this issue Apr 18, 2024 · 0 comments
Assignees
Labels
bug Something isn't working hilla Issues related to Hilla Impact: High Severity: Major

Comments

@Feuerwerk
Copy link

Describe the bug

When validating an optional field which is bound to a text-field based widget (e.g. vaadin-text-field, vaadin-number-field.....) and having a validator registered to that field, once the field gets invalid, this state is permanent.
The field stay red but the error message can go away.

protected firstUpdated(_changedProperties: PropertyValues) {
    super.firstUpdated(_changedProperties);
    const model = this.binder.model;
    this.binder.for(model.text).addValidator(new Size({
        message: 'max 5 characters',
        min: 0,
        max: 5,
    }));
}

render() {
    const model = this.binder.model;
    return html`<vaadin-text-field ${field(model.text)}></vaadin-text-field>`;
}

As a workaround you can add for example the required attribute to the textfield or override checkValidity with an implementation which always return true to get it working again
<vaadin-text-field ${field(model.text)} . checkValidity="${() => true}"></vaadin-text-field>

This seems due to InputConstraintsMixin.checkValidity behaving differently depending on constraints (like required for example) present on the input field. When there is no constraint on the input field checkValidity simply remembers the previous invalid state and keep that.

Expected-behavior

I expect that the invalid status gets updated every time the field is changed by the user

Reproduction

Here is a modified starter project which demonstrates the bug. Just follow the instructions in the browser.
The interesting code changes are only in frontend/views/main-view.ts
skeleton-starter.zip

System Info

Hilla: 2.5.7

@Feuerwerk Feuerwerk added bug Something isn't working hilla Issues related to Hilla labels Apr 18, 2024
@Lodin Lodin self-assigned this Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hilla Issues related to Hilla Impact: High Severity: Major
Projects
None yet
Development

No branches or pull requests

3 participants