Skip to content

_hasInputValue is not updated on programmatic input value change #5410

Closed

Description

@vursen

Description

The _hasInputValue property doesn't get updated when a field component clears or reverts its input value programmatically. The reason is that there is no corresponding input event in that case which can update _hasInputValue.

This becomes a significant issue when it comes to Flow component validation:

Example 1:

  1. Type 1/1/ into a DatePicker – triggers _hasInputValue to become true
  2. Press Esc to close the dropdown.
  3. Result: the DatePicker is red despite no visible value.
Screen.Recording.2023-01-26.at.19.41.06.mov

Example 2:

  1. Type 12:00 into a TimePicker with the clear button visible – triggers _hasInputValue to become true
  2. Press Enter to commit the value.
  3. Click on the clear button.
  4. Result: the TimePicker is red despite no visible value.
Screen.Recording.2023-01-26.at.19.42.00.mov

Expected outcome

_hasInputValue should be updated whenever a field component of the user changes the input value programmatically.

Affected components

Basically, any component that supports the _hasInputValue property is potentially prone to this issue.

Environment

Vaadin version(s): 24.0
OS: Mac OS

Additional context

Related to vaadin/platform#3066

Activity

  1. changed the title [-]The _hasInputValue property is not updated on programmatic input value clear[/-] [+]The _hasInputValue property is not updated on programmatic input value change[/+] on Jan 26, 2023
  2. vursen commented on Jan 27, 2023

    @vursen
    ContributorAuthor

    Possible solution: Introduce an inputElementValue getter and setter in InputMixin (we have such getters and setters in some components already) and use those wherever there is a need for updating value instead of direct inputElement.value = '...' assignments.

  3. changed the title [-]The _hasInputValue property is not updated on programmatic input value change[/-] [+]`_hasInputValue` is not updated on programmatic input value change[/+] on Jan 30, 2023
  4. self-assigned this
    on Feb 8, 2023
  5. vursen commented on Feb 22, 2023

    @vursen
    ContributorAuthor

    There is one complication that I didn't realize immediately. To avoid Flow validation running with an outdated hasInputValue, the value-changed event – which triggers validation – should always come after has-input-value-changed. This is one of the things to take into account in this ticket.

  6. vursen commented on Feb 24, 2023

    @vursen
    ContributorAuthor

    Introduce an inputElementValue getter and setter in InputMixin (we have such getters and setters in some components already) and use those wherever there is a need for updating value instead of direct inputElement.value = '...' assignments.

    In DatePicker's dropdown, you can select and deselect a date with Space which immediatelly affects the DatePicker value. If we simply sync _hasInputValue with the input value, after deselecting the date, DatePicker will have no value but _hasInputValue will be true because the date is still focused and, for this reason, displayed in the input element. Considering that, the right approach will be to reset _hasInputValue on programmatic input value changes.

    This is how it will work in the DatePicker case:

    • The user enters 1/1/ (hasInputValue becomes true).
    • That causes the dropdown to open.
    • The user moves focus to another date in the dropdown.
    • That causes the input element value to change to the focused date (hasInputValue becomes false as it's not user input anymore).

    With this approach, it may feel like the property should be rather called _hasUserInput. That's a valid point. Maybe we'll rename it at some point.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions