Issue with Constraint validation related pages: Not obvious only works on user input
MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation Also applies to: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation and maybe other related validation pages
What information was incorrect, unhelpful, or incomplete?
There is no mention that the methods .validity, .checkValidity() and .reportValidity() and HTML5 validation in general only work when the user has changed the input directly. For context the <input type="text"> does include a small one line mention of this under the minlength and maxlength attributes:
Constraint validation is only applied when the value is changed by the user
I was tracking down a bug in our app where .reportValidity() was not triggering a message even though minlength was set. It came down to us using a controlled input which always set the .value property of the input on change which meant it didn't count as being changed by the user anymore which in turn meant the validity checks didn't work. It took me a while to find that one sentence on the <input> page and the fact that the actual validity pages did not corroborate that fact made me question whether this was the cause until I tested it myself.
Specific section or headline?
Maybe under the base "Concepts and usage" section on the API page itself and maybe under "Constraint validation process" on the second page
What did you expect to see?
I would really like to see one of those blue "note" blocks somewhere on the validation pages that says something along the lines of "validation will not have any effect on values set programmatically" and maybe expand that it's only evaluated on user input. I'm not sure the exact wording that's necessary and maybe not even in a callout like the note blocks but there should be some mention of this interaction on those pages in case you miss it on the <input> page itself
Did you test this? If so, how?
MDN Content page report details
- Folder:
en-us/web/api/constraint_validation - MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation
- GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/api/constraint_validation/index.html
- Last commit: https://github.com/mdn/content/commit/d5cf56f90ed1268223b96501149a7ca40b276438
- Document last modified: 2021-02-04T10:39:33.000Z