What is triggering Unobtrusive Validation check in asp.net MVC 3
Asked Answered
B

1

6

I'm trying to figure out how unobtrusive validation works in asp.net mvc 3.

I would like to know what is triggering the validation check when I click to submit the form. How is the script jquery.validate.unobtrusive.js bound to the form submit event ?

I also would like to know how can I manually prevent/trigger this check.

Bromidic answered 20/12, 2012 at 8:42 Comment(0)
S
8

jquery.validate.unobtrusive is a validator for jquery.validate. It is like a extension.

jquery.validate.unobtrusive implements all the events and jquery.validate use it.

You can look into the jQuery.validate.js file and see that it uses the submit of the form.

// validate the form on submit
this.submit( function( event ) {
   ...

If you want to trigger the validation by yourself you can call

$("#myform").valid()
Strict answered 20/12, 2012 at 8:56 Comment(3)
Thanks for your answer ! I've figured out that $("#myform").validate() do not work to trigger unobtrusive validation I've got to call $("#myform").valid() for the unobtrusive validation to be triggered. Does that sound normal to you ?Bromidic
Oh yes right. I mixed it up. Sorry for the confusion. My answer is updated.Strict
Ok thanks for you answer you've pointed me to the right direction :-) I didn't realized that jquery unobtrusive validation is an extension the the actual jquery validate.Bromidic

© 2022 - 2024 — McMap. All rights reserved.