Like no other form validation library, simply write in English your requirements inside your form HTML tags, Parsley will do the rest!
No need to write even a single Java Script line for simple form validation.
The “validation descriptor” is nothing but a string specifying the type of validation to be performed.
Each field in the form can have zero one or more validations. More info & downloads where Do My Validation One() and Do My Validation Two() are custom functions for validation.
I've coded a working form, all checks are great but for some reason the hardest part is trying to stop form submission before validation.
So i have places to insert the stop validation code, but just cant find any that works.
I tested your first piece of code on a form and it does not work at all.
Tried setting it up on onsubmit on both form and button and no go.
To find out which value (if any) has been selected, you need to loop through the array until you find which one has been selected: In the case of a single radio button we have nothing to loop through so just return either it's value, if the radio button is checked, or false.
Normally you would modify this so that you could submit or not submit the form based on the number of items selected. For example, a text input that only needs to have a value if a checkbox is checked: Using simple logical operators and the functions supplied above you can do all sorts of client-side form validation.
To take things a step further you can even explore Ajax Form Validation which lets you supply real-time feedback using server-side scripts triggered by Java Script events.
In other words if the first condition fails, the second condition will not be tested and so forth.
Only when all conditions have been satisfied do we reach the command, in which case the form will be submitted.