How to set the minimum delay for BlockUI?

I am trying to set the minimum display of BlockUI, but with a problem. No matter what value I put in setTimeout, the element is immediately unlocked.

Here I configure the jQuery ajaxForm plugin options:

var options = { type: 'POST', contentType: 'application/json; charset-utf-8', dataType: 'json', complete: function () { setTimeout($('#MyElement').unblock(), 5000); } }; 

And here I show the BlockUI in "MyElement" when the submit button is clicked.

  $('.submit').click(function () { window.showBlockUI($('#MyElement')); }); 

Any ideas? Thanks.

+4
source share
1 answer

You call the function in your setTimeout() without passing a reference to the function, so it runs immediately and passes the result of returning this function to setTimeout() . Thus, it is executed immediately.

Change it like this:

 complete: function () { setTimeout(function() {$('#MyElement').unblock()}, 5000); } 

or in a slightly less compact form where you can see it better:

 complete: function () { setTimeout(function() { $('#MyElement').unblock() }, 5000); } 
+1
source

All Articles