Form Validation: Limit custom validation reset to own validation#5631
Merged
Form Validation: Limit custom validation reset to own validation#5631
Conversation
**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
zachmargolis
approved these changes
Nov 23, 2021
| @@ -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"> | |||
Contributor
There was a problem hiding this comment.
LOL at all these backslashes
Contributor
Author
There was a problem hiding this comment.
LOL at all these backslashes
Yeah... tbh, I can't remember the reasoning behind this. Should probably have picked a simpler pattern 🤷
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extracted from: #5619
Why:
form-validation.js.Previously, changing the value of an input within a form subject to
form-validation.jsbehavior would reset custom validity, and often introduced race conditions where a custom implementation's custom validity behavior would be unexpectedly reset.Steps to reproduce:
Previously, if
validated_form_forwas 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-inputapplying a custom validity reflecting the invalid phone number, a race condition occurred whereform-validation.jswould reset that custom validity immediately afterward. With the changes here, the reset no longer occurs, and@18f/identity-phone-inputis 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).