Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a script after validation with jquery.validate.unobtrusive

I am using ASP.NET MVC 3 with unobtrusive validate JavaScript. I am also using jQuery UI tabs, and I would like to select a tab who contains an element with an invalid message.

So, to do that I need to call a script just after the jquery.validate is evaluated.

I tried some like this:

$(':submit').submit(function () {
    var invalidField = $(".input-validation-error");
    if (invalidField ) {
        tabid = //some script to detect wich tab contains the invalidField
        $('#someTabed').tabs('select', tabid));
    }
});

It works, but just if I click the submit button TWICE. Which means this method is not called after the event I would like.

So I need to know how to intercept the validate method made by unobtrusive validate, to put my method after that.

like image 552
iuristona Avatar asked Jul 30 '11 02:07

iuristona


1 Answers

I don't think you can intercept the method (I could be wrong but all the postings I've ever seen on this all manually call this.valid), instead you will have to call the validation yourself on post.

How to hook into error of jQuery validate unobtrusive in MVC 3?

like image 75
Adam Tuliper Avatar answered Jan 03 '23 12:01

Adam Tuliper