Jay2001
Jay2001

Reputation: 59

Hide form submit button with jQuery only when for actually submits

For a while I have been using the following code...

$("input[type=submit]:not(.noHide)").one('click', function() {
    $(this).hide();
    $(this).click(function () { return false; });
});

to disable form submit buttons on click, primarily to avoid double clicks submitting twice.

I now have a form or two with required fields...

<input type="date" name="DatePurchased" required>

and this kind of breaks since the submit button is now gone once the omission is corrected.

Is there a way to disable the button only after a successful submission and not just a click?

Upvotes: 0

Views: 47

Answers (1)

Hans Roerdinkholder
Hans Roerdinkholder

Reputation: 3000

Use the submit-event instead.

$("input[type=submit]:not(.noHide)").on('submit', function() {
    if ($(this).not(':visible')) {
        return false;
    }
    $(this).hide();
});

Upvotes: 1

Related Questions