Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force form client-side validation in or before $.ajax()

I have a form and unobtrusive validations are enabled. By default in submit method client side validation gets triggered and (if you have any errors) the form looks like this:

enter image description here

The validation happens even before any data gets sent to the server.

Now this behavior doesn't work if you want to use $.ajax method. Client side validation doesn't work. You have to manually check all the fields in your javascript, losing all the beauty of DataAnnotations.

Is there any better solution? I could've use jquery's submit() but I guess it doesn't have callback like $.ajax.

like image 888
iLemming Avatar asked May 24 '11 16:05

iLemming


1 Answers

Oh...

if (form.valid()) // do submit
like image 180
iLemming Avatar answered Oct 21 '22 00:10

iLemming