I'd like to create attribute validation for a check box or radio buttons but have that validation not be enforced when it is not applicable. Unfortunately, disabling the control or making it read-only does not turn off the validation.
Does anyone know how from jQuery or JavaScr开发者_如何学Goipt, I could stop the validation when some state was true (the control was disabled or some other checkbox was unchecked, for example)?
Thanks, Paul
I believe this post will help.
How can I add, remove, or swap jQuery validation rules from a page?
To sum it up here's the code
var settings = $('form').validate().settings;
delete settings.rules.rightform_input1;
delete settings.messages.rightform_input1;
Setting would look something like this.
$('form').validate({
rules: {
leftform_input1: { required: true },
leftform_input2: { required: true }
},
messages: {
leftform_input1: "Field is required",
leftform_input2: "Field is required"
}
});
精彩评论