I’m tring to use jquery validate to show some errors returned from the server.
I’m using the validator.showErrors() method to do this.
I can get the method to work as per the example here.
var validator = $("#myform").validate();
validator.showErrors({"firstname": "I know that your firstname is Pete, Pete!"});
What I’m trying to achieve however is to have 2 or more validation errors for the same or different fields. According to the documentation this is possible
Show the specified messages. Keys have to refer to the names of
elements, values are displayed for those elements, using the
configured error placement.Arguments:
errors
Object<String, String>
One or more key/value pairs
of input names and messages.
Looking inside the showErrors method shows the following:
showErrors: function(errors) {
if(errors) {
// add items to error list and map
$.extend( this.errorMap, errors );
this.errorList = [];
for ( var name in errors ) {
this.errorList.push({
message: errors[name],
element: this.findByName(name)[0]
});
}
// remove items from success list
this.successList = $.grep( this.successList, function(element) {
return !(element.name in errors);
});
}
this.settings.showErrors
? this.settings.showErrors.call( this, this.errorMap, this.errorList )
: this.defaultShowErrors();
}
I have tried the following:
validator.showErrors({ "Id": "I know that your firstname is Pete, Pete!" },{ "Id":"test2"});
but it still only shows the first error.
Any idea the correct format to use to get it to show multiple errors
So it would appear the correct format is
Unfortunately the second error is shown right next to the first error, so my next issue is to find a nicer way to format these.