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 ?
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.
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.
There are some usefull samples here. So, email field validation in form will look so: $("#myform"). validate({ rules: { field: { required: true, email: true } } });
var validator = $("form").validate() validator.errorList
will show the array of errors that are holding back the form from submiting.
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); }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With