Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
60
rated 0 times [  62] [ 2]  / answers: 1 / hits: 31764  / 14 Years ago, tue, september 28, 2010, 12:00:00

Do we have any function which returns all the error messages while validating a form?



I have tried using the defaultshowerros() function but it returns the error message for the element it is currently validating. How can I get all the error messages of the whole form?


More From » jquery

 Answers
99

If you store a reference to the validator, for example:



var validator = $(form).validate();


You can call .errors() or .invalidElements() at any time on it, for example:



var errors = validator.errors(); //get the error elements, the actual labels
var errors = validator.invalidElements(); //the invalid elements themselves


If you're not really after the errors and just want them to appear in once place, use the built-in errorLabelContainer and wrapper options, for example:



<ul id=errors></ul>


And reference that:



$(form).validate({ errorLabelContainer: #errors, wrapper: li });


And your errors would appear all in that list, which is also automatically shown/hidden if there are/aren't any errors.


[#95482] Friday, September 24, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carlymykalac

Total Points: 740
Total Questions: 91
Total Answers: 91

Location: Sudan
Member since Thu, May 7, 2020
4 Years ago
;