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

Input components chained validation logic #3066

Closed
14 tasks
yuriy-fix opened this issue Jun 15, 2022 · 3 comments
Closed
14 tasks

Input components chained validation logic #3066

yuriy-fix opened this issue Jun 15, 2022 · 3 comments
Labels
acceptance criteria used for the acceptance criteria checklist DS Design System feature (e.g. component) v24

Comments

@yuriy-fix
Copy link
Contributor

yuriy-fix commented Jun 15, 2022

Description

Chaining validation in the components when web-component, flow counterpart and Binder are used together.
Validation should happen in the order 1. web-component, 2. Flow component, 3. Binder.

Problems with current validation behavior

  • Currently client-side validation is disabled when Flow component is used.
  • Binder is not taking into account validation constraints of flow components.
  • The field cannot be validated on blur when used with flow counterpart.
  • Fields are not validating client values that cannot be represented as valid server-side values (e.g. qwerty string is not sent to flow component DatePicker as it's not of type LocalDate)

Use cases

As a developer
I want my field to be validated on blur / value changed regardless of flow component, Binder usage.

As a developer
I want my field's validation constraints to be chained through web-component, flow component and Binder.

Acceptance criteria

  • When used with Flow, web-components
    • should be able to set themselves invalid
    • should NOT be able to set themselves valid
  • Web-components should notify their Flow counterparts when client side validation is done, and
    • it should trigger server-side validation
    • it should trigger Binder validation
  • Input components should implement HasValidator and provide getDefaultValidator
  • Input components should override addValidationStatusChangeListener to trigger Binder validation when web-component and Flow component validations are done.

Related Flow issue

General criteria

  • APIs reviewed
  • Performance
  • UX/DX tests in Alpha
  • Documentation:
  • How to test?
  • Limitations:
@vursen
Copy link

vursen commented Sep 5, 2022

The new validation behavior is now available under the feature flag in v23.2 for the following components:

  • TextField
  • TimePicker
  • DatePicker
  • DateTimePicker

To try it out, enable the feature flag in your application by adding the following to vaadin-featureflags.properties:

com.vaadin.experimental.enforceFieldValidation=true

@vursen
Copy link

vursen commented Jun 20, 2023

Here is a summary of the changes implemented as part of this ticket:

Binder Takes Into Account Component Constraints

Every field component provides its own set of constraints such as required, minlength, pattern, and so on.

Before

When using Binder, it ignored component constraints, so they would only affect UX but not the server-side invalid state.

After

Component constraints are integrated into Binder validation. Binder checks the value against constraints before running custom validators.

The only exception is the required constraint which doesn't participate in Binder validation since Binder provides its own asRequired validator.

Limitations

  • It's currently not possible to configure custom error messages for constraints, but there are plans to improve that, see flow-components#4618
  • It's currently not possible to get Binder back to ignore constraints as before, other than not using constraints at all.

Blur Triggers Server-Side Validation

Before

Both constraint and binder validation were only triggered on value change while client-side validation was completely ignored.

After

The server-side validation timing is aligned with client-side validation, meaning that whenever the web component validation occurs, it triggers the corresponding validation in the Flow component.

In practice, it means that the server-side validation will be also performed on blur. This solves issues where required fields didn't become invalid after the first user interaction.

Limitations

  • The component validates on blur even when the user leaves it without typing anything. This behavior results from the web component, which validates on blur to detect possible bad input (web-components#6146).
  • The server-side validation can be triggered more frequently than necessary. For example, if you edit a Text Field and then blur, both value-changed and blur events will fire at the same time, resulting in double validation in a single round-trip (flow-components#4390).

Entering Bad Input Invalidates The Component

DatePicker, IntegerField, and some other similar components only accept user input that can be parsed as a LocalDate, Integer, etc. Otherwise, the value falls back to null on the server.

Before

Entering bad input didn't invalidate the component because the server treated this case as an empty value.

After

The server knows if the user has entered some input. When it cannot be parsed, it's considered bad input and will cause constraint validation to fail once the user presses Enter or removes focus from the component.

Affected Components

The above changes apply to the following components:

  • DatePicker
  • TimePicker
  • DateTimePicker
  • TextField
  • NumberField
  • IntegerField
  • BigDecimalField
  • PasswordField
  • EmailField
  • TextArea
  • Select
  • ComboBox
  • MultiSelectComboBox
  • RadioGroup
  • CheckboxGroup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acceptance criteria used for the acceptance criteria checklist DS Design System feature (e.g. component) v24
Projects
Archived in project
Development

No branches or pull requests

3 participants