I am using ASP.NET MVC with jquery and jquery validation.
I have created one page that contains some entries name and address and etc...
On submit click I want to validate the details as I have given in view model as required field.
All running fine, validation fire successfully.
I want to get all the error list of the required fields.
I am getting it like this:
var validator = $("#formname").validate();
for (var i = 0; i < validator.errorList.length; i++) {
console.log(validator.errorList[i].message);
}
All running fine here as well but the problem I am facing here is I got the errorList on second click / submit not on first click.
I want all the errorList on first click / submit.
Why it is coming on second click I don't understand?
Please who has done this issue or solved it, help me to solve this.
Any help will be appreciated.
My code example:
$('#formname').submit(function () {
$.validator.unobtrusive.parse($('#formname'));
var $form1 = $('#workoerderDetails');
//Here I try to get all the error list starts
var validator = $("#formname").validate();
for (var i = 0; i < validator.errorList.length; i++) {
console.log(validator.errorList[i].message);
}
//Here I try to get all the error list ends
if ($form1.valid()) {
//my code if no any validation fire
}
else{
return false;
}
});
$form1 is running perfectly fine but I want to get all the error list from that so I use validator variable where I get all the errorlist in for loop but it gives me on second submit / click.
.validate()
method since the Unobtrusive plugin is already doing that automatically. Your instance will always be ignored.... this may explain the weird timing of the click event, although we can't see enough code to know that either. – Peta