invalidHandler
完成有效条目后,如何让 jQuery Validate 插件更新错误计数器?
$(document).ready(function () {
$("#report-listing-form").validate({
rules: {
'listing-report-email': {
required: true,
email: true
},
'listing-report-name': {
required: true
},
'listing-report-phone': {
number: true,
minlength: 7,
maxlength: 12
},
'contact-msg': {
required: true,
maxWords: 1000
}
},
errorPlacement: function(error, element) {
return false; // will suppress error messages
},
invalidHandler: function (event, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var message = (errors == 1) ? '1 invalid field.' : errors + ' invalid fields.';
$("#err_report-listing-form").html(message).addClass("text-error");
}
},
submitHandler: function (form) {
alert('valid form');
return false;
}
});
});