open-wc / form-participation

Helper, mixins, tools, and more for supporting your custom elements in participating in an ancestor form.
MIT License
53 stars 7 forks source link

fix(form-control): fix validators, fix incremental validationMessage storage, add tests #38

Closed michaelwarren1106 closed 1 year ago

michaelwarren1106 commented 1 year ago

Fixed the validationMessage issue and added a test for it.

As of this PR, the validationMessage that is set will only ever be the message from the first invalid validator. The validity state will get passed though each loop, but not the message. This will enable messages shown as error messages to be "iterative" while the validity state is always full with multiple errors. This fix also prevents the issue where the last invalid validator message will always overwrite. So folks can "order" their validators in order of importances and ease of correction - for example having the requiredValidator be first and always show that message first if invalid.

Also noticed an error with the existing default validators. The maxLengthValidator was set to use the rangeOverflow validity key, but the correct key for maxLength is tooLong. Similar for minLengthValidator, the key was set to rangeUnderflow, but the correct key is tooShort.

The rangeOverflow and rangeUnderflow validity keys refer to the min and max properties that deal with numbers. tooLong and tooShort deal with minlength and maxlength and strings.

michaelwarren1106 commented 1 year ago

the delayedValidationTarget test seemed flaky on my end locally. Would love to make sure its not something im doing wrong. Automated tests on GH seemed to pass for me tho. Might be something worth taking a look at? Seems like a race condition.