To process the form, I use the following code (for test only):
$(document).on("beforeSubmit", "#test-form", function (event, messages) {
$(this).find(':submit').attr('disabled', true);
console.log('Test new form');
return false;
});
But, despite the fact that I am making the submit button inactive, we can see in the console that the form is submitted at least twice when I quickly click on the button. As a fix, temp wrote the following code:
$(document).on("beforeValidate", "form", function(event, messages, deferreds) {
$(this).find(':submit').attr('disabled', true);
console.log('BEFORE VALIDATE TEST');
}).on("afterValidate", "form", function(event, messages, errorAttributes) {
console.log('AFTER VALIDATE TEST');
if (errorAttributes.length > 0) {
$(this).find(':submit').attr('disabled', false);
}
});
$(document).on("beforeSubmit", "#test-form", function (event, messages) {
console.log('Test new form');
return false;
});
But not sure if this is a good solution or not. How to fix this problem?
Thanks in advance!
source
share