Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC check form input is valid on submit

I have a form that, when submitted, shows a busy animation and disables the submit button.

Anyone know how to query Microsoft's Sys.Mvc.FormValidation to see if the form passed its test so I can prevent the busy animation showing if the form hasn't actually been submitted? Is there some other work-around?

At present my client side JavaScript looks like this:

$('form').submit(function() {
    $('input[type=submit]', this).attr('disabled', 'disabled');
    ShowBusy();
});

Cheers, Gavin

like image 683
Gavin Avatar asked Jan 13 '10 21:01

Gavin


1 Answers

I gave up in the end and plugged in the JQuery validation library instead using the Microsoft ASP.NET MVC 2 RC and the MicrosoftMvcJQueryValidation.js library file from the "futures" project to automatically wire up everything for me.

This article explains the process: http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx

So with JQuery validation in effect all I needed to do was make a call to valid()...

$('form').submit(function() {
    if ($('form').valid()) {
        $('input[type=submit]', this).attr('disabled', 'disabled');
        ShowBusy();
    }
});
like image 172
Gavin Avatar answered Sep 19 '22 13:09

Gavin