Reputation: 59
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
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