Skip to content

Form Validation: Limit custom validation reset to own validation#5631

Merged
aduth merged 3 commits intomainfrom
aduth-form-validation-custom
Nov 23, 2021
Merged

Form Validation: Limit custom validation reset to own validation#5631
aduth merged 3 commits intomainfrom
aduth-form-validation-custom

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Nov 23, 2021

Extracted from: #5619

Why:

  • To avoid conflicts between form-validation custom validation and other custom validation which may apply to an input (e.g. a component implementation).
  • For consistency of form rendering to include baseline validation (e.g. required field validation).
  • To restore test coverage for remaining pattern type validation in form-validation.js.
  • To reflect latest changes where SSN validation is handled by adjacent visible text element as of LG-5040 refactor text field #5468.

Previously, changing the value of an input within a form subject to form-validation.js behavior would reset custom validity, and often introduced race conditions where a custom implementation's custom validity behavior would be unexpectedly reset.

Steps to reproduce:

  1. Log in
  2. On Account dashboard, click "Add phone number"
  3. Enter an invalid phone number, like "513555"
  4. Toggle delivery method to "Phone"

Previously, if validated_form_for was used in these forms, the "Submit" button would become unexpectedly enabled, since the form is valid at this point. It was valid only because despite @18f/identity-phone-input applying a custom validity reflecting the invalid phone number, a race condition occurred where form-validation.js would reset that custom validity immediately afterward. With the changes here, the reset no longer occurs, and @18f/identity-phone-input is put back in full control of managing custom validity.

The default required and pattern mismatch validation is trending toward eventual removal in favor of explicit error texts adjacent to the invalid input (LG-5040).

**Why**: To avoid conflicts between form-validation custom validation and other custom validation which may apply to an input (e.g. a component implementation).
**Why**: Consistency of form rendering and validation (e.g. required field messaging)
**Why**: It is now handled by adjacent inline text element as of #5468
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -57,6 +57,7 @@ describe('form-validation', () => {
<input type="text" aria-label="required field" required class="field">
<input type="text" aria-label="format" pattern="\\\\A\\\\d{5}(-?\\\\d{4})?\\\\z">
<input type="text" aria-label="format unknown field" pattern="\\\\A\\\\d{5}(-?\\\\d{4})?\\\\z" class="field">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL at all these backslashes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL at all these backslashes

Yeah... tbh, I can't remember the reasoning behind this. Should probably have picked a simpler pattern 🤷

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants