in jquery.validate
my requirement:
the input-text will be validated only if the checkbox in the same row is be checked!
$("[name='ck']").click(function () {
var text = $(this).parent().parent().find("[name='t']");
if ($(this).attr("checked") == "checked") {
text.addClass("required");
} else {
text.removeClass("required");
}
});
the code is OK! but when i change the rule to {required:true,number:true,max:5} ,it is not work!
only the input-text of the first checkbox be checked will be validated! when the second checkbox be clicked,the relevant input-text will not be validated.
so
addClass("{required:true,number:true,max:5}");
Is the way to Add/remove validation rules Dynamically is NOT legal, but why it will be work only once!
addClass()is for adding CSS classes. It doesn't work for you because the string{required:true,number:true,max:5}is not a CSS class.