In my MVC application, there are multiple pages where users submit a form by clicking a Submit button. Occasionally, users may click the button multiple times if they don't see an immediate response, causing the form to be submitted twice. To address this issue, I have implemented the following JavaScript code:
// This JavaScript code disables the Save button upon form submission to prevent accidental double posting.
$('#form').submit(function () {
$(this).find('input[type=submit]').prop('disabled', true);
return true;
});
While this solution effectively prevents double form submission, it poses a challenge when client-side validation errors occur. In such cases, the Submit button remains disabled even though the form was not posted, preventing users from submitting the form again. Is there a modification that can be made to detect client-side validation errors and either avoid disabling the Submit button or re-enable it accordingly?