0

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?

Jay2001
  • 49
  • 6

1 Answers1

1

Use the submit-event instead.

$("input[type=submit]:not(.noHide)").on('submit', function() {
    if ($(this).not(':visible')) {
        return false;
    }
    $(this).hide();
});
Hans Roerdinkholder
  • 2,963
  • 1
  • 17
  • 30