foundation-sites icon indicating copy to clipboard operation
foundation-sites copied to clipboard

fix: Abide validateInput - remove existing error classes before adding error classes

Open asineath-onpoint opened this issue 2 years ago • 1 comments
trafficstars

fix: Abide validateInput - Remove all existing validation error classes from an input before applying current error classes, in order to remove error messages for validation rules that have been satisfied by the most recent value change, even if other rules are still invalid

Description

In this scenario, an input has two validation rules, each rule with a corresponding validation message using the "data-form-error-on" attribute. First enter a value that both validation rules consider invalid. Then change the value to something that one validation rule considers invalid but the other considers valid. Both validation messages still remain visible.

In the existing "validateInput" logic, the error classes (by default: is-invalid-label, is-visible) only get removed from the validation messages once the input passes all validation rules. This results in some error messages staying visible even when their rules have since been satisfied, resulting in inaccurate feedback to the user.

This small update adjusts the relevant portion of "validateInput" to first remove all error classes and then add the error classes based on the current set of "failedValidators".

Types of changes

  • [ ] Documentation
  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (anything that would change an existing functionality)
  • [ ] Maintenance (refactor, code cleaning, development tools...)

Checklist

  • [x] I have read and follow the CONTRIBUTING.md document.
  • [x] The pull request title and template are correctly filled.
  • [x] The pull request targets the right branch (develop or develop-v...).
  • [x] My commits are correctly titled and contain all relevant information.
  • [x] I have updated the documentation accordingly to my changes (if relevant).
  • [x] I have added tests to cover my changes (if relevant).

asineath-onpoint avatar Sep 18 '23 18:09 asineath-onpoint