HTML Forms have powerful validation mechanisms that are often overlooked. Attributes like “required” and methods like setCustomValidity provide different ways to add constraints to input fields. However, the imperative nature of setCustomValidity can lead to cumbersome implementations, as shown in the example provided. The lack of a declarative custom validity attribute in the HTML Spec is highlighted, and a workaround using userland implementation is suggested. The article explores how setCustomValidity can handle complex validation scenarios, such as async checks and dependent fields. Overall, the author advocates for a declarative approach to validation to enhance code readability and maintainability.
https://expressionstatement.com/html-form-validation-is-heavily-underused