Add form wide validation
See original GitHub issueCurrent validation is field level only. It would be great if there was the ability to validate the form as a whole with the error message appear above or below the form (preferably configurable).
My use case is I have a password
and passwordConfirm
fields which I want to match. Putting a validator on one or both fields won’t work as they are dependant on each other.
An alternative approach would be a formOption which runs all field validator whenever any field changes.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Client-side form validation - Learn web development | MDN
The simplest HTML validation feature is the required attribute. To make an input mandatory, add this attribute to the element. When this ...
Read more >The Easiest Way To Add Validation To Your Forms - Tutorialzine
In this tutorial we will show you how to add validation rules to your forms, using only native HTML input attributes. Project Overview....
Read more >The Complete Guide to HTML Forms and Constraint Validation
How much do you know about HTML5 form validation? Even if you know a lot, we bet you'll learn things you didn't know...
Read more >Form Validation: Why It Matters and How to Get It Right - CXL
Inline validation is a wonderful way to reduce friction in forms. It's becoming more and more common, probably because we've seen compelling ...
Read more >Web Form Validation: Best Practices and Tutorials
With client-side validation, form never gets submitted if validation fails. Validation is being handled in JavaScript methods that you create ( ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here’s a custom validator I wrote for comparing two fields, and a JSFiddle example
https://jsfiddle.net/zoul0813/rukxozdk/ - using _.isEqual for more complex comparisons
https://jsfiddle.net/zoul0813/rukxozdk/4/ - without lodash, doing simple
"a" == "b"
checkJust add this to your project, then add
isEqualTo
to the validator array for the second password. Add anequals
property to the second password fields schema pointing to the first passwords model.@icebob, @will-fgmnt here’s a rough draft of what I’m working on.
https://jsfiddle.net/zoul0813/z3up3rwo/
Basically just a Proxy wrapper for ValidateJs, it looks at the field’s
rules
property.ValidateJs.equality
or any of the other validators works. You can also run multiple ValidateJs validations just by adding them to the “rules” property and calling one of the virtual functions to trigger them all (therules
property is just passed tovalidate()
as the constraint). For simple usage, the function called on ValidateJs creates a"functionName": true
constraint (for things like{ email: true }
).This is just a rough draft, and I plan to clean this up quite a bit … I also hope to be able to get “form-wide validation” working so that when a field is changed, all the fields revalidate. Likely going to stick with the “field by field” validation, but plan to figure out how to get the fields to revalidate themselves by listening for a validation event.