How can I display both individual error messages and summary for the jQuery plugin?
I actually found a similar question , but it just references some hooks I can use, but I'm not sure where to start.
I got the displaying individual error messages part, but I need to display the summary in an alert box on submit, and plugin can be found here.
Just found out how, thanks for David's code, and on my follow-up question - The alert box would be "First Name: Please enter a valid First Name".
Code below:
$(document).ready(function() {
var submitted = false;
('.selector').validate({
showErrors: function(errorMap, errorList) {
if (submitted) {
var summary = "You have the following errors:
";
$.each(errorMap, function(key, value) {
summary += key + ': ' + value + "
";
});
alert(summary);
submitted = false;
}
this.defaultShowErrors();
},
invalidHandler: function(form, validator) {
submitted = true;
}
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…