Skip to content

Instantly share code, notes, and snippets.

@MubinSayed
Last active April 5, 2021 18:56
Show Gist options
  • Save MubinSayed/1eb5fb1b4b51ade87f25953dd0b55359 to your computer and use it in GitHub Desktop.
Save MubinSayed/1eb5fb1b4b51ade87f25953dd0b55359 to your computer and use it in GitHub Desktop.
Get Error List in jQuery .validate plugin Invalid Handler
// In the invalidHandler, you are passed two arguments, a jQuery.Event and the validator object.
// You don't need to call validate within your invalidHandler to get the validate object.
// Further, the validator object has a properties called errorList and errorMap, which contain the information you are looking for.
invalidHandler: function(e,validator) {
//validator.errorList contains an array of objects, where each object has properties "element" and "message". element is the actual HTML Input.
for (var i=0;i<validator.errorList.length;i++){
console.log(validator.errorList[i]);
}
//validator.errorMap is an object mapping input names -> error messages
for (var i in validator.errorMap) {
console.log(i, ":", validator.errorMap[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment