Calling blockUI and unblockUI in combination with jQuery validator plugin

Posted by Tim Stewart on Stack Overflow See other posts from Stack Overflow or by Tim Stewart
Published on 2010-02-27T05:39:56Z Indexed on 2010/03/09 10:36 UTC
Read the original article Hit count: 455

Filed under:
|
|

I have a very complex form with the validation working correctly. However, since it can take awhile for the validation to complete, I'd like to use blockUI to be called when I click the form's submit button to prevent confusion and double-submissions. I can't quite figure out how to do this.

My code looks like this:

$("#credential").validate({
     rules: {
              EngId: {
                 required: true
                 }
             ClientAccount: {
                 required: true
                 }
              ...
        }

and I'm calling the validation with several buttons (using their click function) depending on selections in the form, often disabling some of the rules:

$("#buttonname").click(function() {
   $("#fieldname").rules("remove");
   ...
   $("#credential").submit();
});

What I can't figure out is where the blockui and unblockui calls would go so that when the user clicks the button, before validation starts, blockui does its magic, and if the validation finds a problem, unblockui is called and enables the form again.

I'm pretty new to Jquery and I can't find any examples that I've been able to implement successfully. I would appreciate any help anyone could give (please excuse if this has been covered before).

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about form-validation