Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see jQuery validation list of elements with errors

Sometimes, the form won't submit because jQuery has some invalid elements that will not show up in an error message.

How can we see these errors in order to debug more easily ?

like image 477
Dragos Durlut Avatar asked Aug 14 '12 12:08

Dragos Durlut


People also ask

What jQuery Unobstructive validation is?

jQuery is a Javascript library. An unobtrusive validation in jQuery is a set of ASP.Net MVC HTML helper extensions.By using jQuery Validation data attributes along with HTML 5 data attributes, you can perform validation to the client-side.

What is validator addMethod in jQuery?

validator. addMethod( name, method [, message ] ) Description: Add a custom validation method. It must consist of a name (must be a legal javascript identifier), a javascript based function and a default string message.

How check email is valid or not in jQuery?

There are some usefull samples here. So, email field validation in form will look so: $("#myform"). validate({ rules: { field: { required: true, email: true } } });


2 Answers

var validator = $("form").validate() validator.errorList 

will show the array of errors that are holding back the form from submiting.

like image 155
Dragos Durlut Avatar answered Sep 19 '22 14:09

Dragos Durlut


This works for me to get a list of validation errors (ids of error inputs and associated error message):

    if ($('#form').valid()) {          console.log('FORM VALID');      } else {          console.log('FORM INVALID');          var validator = $('#form').validate();          $.each(validator.errorMap, function (index, value) {              console.log('Id: ' + index + ' Message: ' + value);          });      } 
like image 45
RickL Avatar answered Sep 20 '22 14:09

RickL