jquery validate plugin: add a custom method
- by pixeline
I need some guidance on how to add a validation method to the jquery validate plugin. I've gathered that i need to use the plugin's addMethod() function, but how exactly to have it do what i need... Here i am!
My form 's first question is a radio input choice. Each radio input, if selected, shows a sub-question of several checkboxes.
What i would like my validation to do is:
- make sure one radio input is selected
- make sure at least one checkbox pertaining to the radio input is selected.
Basically, out of the validate plugin's own logic, i would count the selector's length, and if there isn't any, return the error message. Something like this:
var weekSelected = ($('input.seasonSelector:checked input.weekSelector:checked',form).length > 0);
if(!weekSelected){
return 'Please select a week inside that season';
}
How to turn that into a validate plugin method ?