On my client-side page I attach a listener to the submit button:
$(function() {
$('button[type="submit"]').click(submitButtonClicked);
});
and I'd like to disable the button and all other form input elements when the button is clicked:
function submitButtonClicked(ev) {
if ($(this).hasClass('disabled')) {
return false; // Reject actions when disabled, preventDefault() and stopPropagation()
}
$('form').find('input, select, textarea, button')
.prop('disabled', true) // This call is the culprit?
.blur();
return true; // Submit form.
}
The above function seems to swallow the event, and no form submit arrives at the server. However, if I remove the prop('disabled', true)
then the form submits just fine, but also all form elements stay enabled and reactive.
Why is that? I assumed that returning true
will cause the event ev
to continue propagating, whether or not the button is being disabled.