Asil Can Bozoğlu
Asil Can Bozoğlu

Reputation: 11

Disable submit button if validation true (jQuery Validation Engine)

I'm using jQuery Validation Engine (https://github.com/posabsolute/jQuery-Validation-Engine) to validate my form. I want to disable submit button to prevent multiple submits if validation is true. I couldn't achieve this with callback functions.

Upvotes: 1

Views: 2173

Answers (2)

davidethell
davidethell

Reputation: 12038

I typically do this:

$('#theform').submit(function() {
    $('#submitbutton').attr('disabled', 'disabled');
});

Of course if you are doing any onsubmit validation that fails you have to reenable the button:

$('#submitbutton').removeAttr('disabled');

Upvotes: 0

Ron
Ron

Reputation: 2790

I always do this trick

$('#yourform').submit(function() {
    if($(this).hasClass('blockSubmit')) return false;
    $(this).addClass('blockSubmit');
    /*
     * organizing data, requesting, responding, et cetra cetra...
     */
    $(this).removeClass('blockSubmit');
});

Upvotes: 1

Related Questions