Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submitting form after using e.preventDefault();

I have a form that I am stopping from submitting with e.preventDefault(). (I've also tried return false).

I would manually tell the form to submit after a short delay, using the code:

$('form').delay(2000).submit();

Unfortunately, e.preventDefault() seems to disable the form from submitting even if it explicitly submitted using the submit() function.

Any idea how I can combine these intentions? I'd like to show a loading screen for a couple of seconds.

Thanks!

like image 553
Chris Nolet Avatar asked Feb 14 '13 01:02

Chris Nolet


1 Answers

$("form").on('submit.blocker', function (e) {
    setTimeout(function () {
        $("form").off('submit.blocker').trigger('submit');
    }, 2000);
    e.preventDefault();
});
like image 61
Explosion Pills Avatar answered Sep 24 '22 06:09

Explosion Pills