我有一个表单,其中文本字段的要求取决于单选字段的值。当检查正确的无线电选项时,该验证第一次可以正常工作。但是,如果我们更改收音机的值,即使检查了收音机的有效选项,文本字段上的错误消息也会保留。任何想法,我如何在错误有效时消除错误?
这是我的验证码:
$().ready(function() {
$("#myform").validate({
rules: {
ff_24: "required",
ff_25: "required",
ff_26: {
required: {
depends: function(element) {
return ($('input[name="ff_25"]:checked').val() == 'Yes');
}
}
},
ff_28: "required",
ff_30: "required"
},
messages: {
ff_24: "This field is required",
ff_25: "This field is required",
ff_26: "This field is required",
ff_28: "This field is required",
ff_30: "This field is required"
},
errorPlacement: function(error, element) {
var container = $('<div />');
container.addClass('tooltip'); // add a class to the wrapper
if (element.attr('type') === 'radio') {
error.appendTo(element.parent());
}
else if (element.attr('type') === 'checkbox') {
error.insertAfter(element.next());
}
else {
error.insertAfter(element);
}
error.wrap(container);
$("<div class='errorImage'></div>").insertAfter(error);
},
success: function(element) {
$(element).addClass("checked");
return false;
}
});
});