When adding or removing an error from an input element, also apply it to inputs with the same name. #40
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.
We had this issue raised on the Umbraco Forms product that uses this library for client side validation.
It seems to me a reasonable general case for input fields, particularly check box and radio button lists, that when adding or removing a class to indicate an error on an input field, that this should be applied to all inputs with the same name.
Hence this PR.
As an example, with a form containing mandatory radio button or check box lists, with
.input-validation-error
styled with red text:Submitting the form triggers the client-side validation and the appropriate classes are added to all fields:
Clicking a single radio or checkbox will currently remove the error only for the one you clicked on, leaving the other indicated as invalid even though now actually it's not.
With this PR all radio buttons will have the class removed.
Similarly for adding errors, previously, if values in a list of checkboxes were selected and subsequently removed, when the last item was deselected, only that one would get the invalid error class. Now all of them do: