jquery validate plugin: add a custom method
Posted
by pixeline
on Stack Overflow
See other posts from Stack Overflow
or by pixeline
Published on 2010-04-16T21:32:25Z
Indexed on
2010/04/16
21:53 UTC
Read the original article
Hit count: 531
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 ?
© Stack Overflow or respective owner