I'm working with Sitecore 10.1 and facing a challenge with Sitecore forms. I want to disable the submit button right after it's clicked. I've attempted some script solutions but haven't found a reliable way that integrates smoothly with Sitecore's form handling.
Below script I tried but it didn't work
<script type="text/javascript">
// Disables submit button and changes its appearance only if the form is valid
$(document).ready(function() {
$('form').each(function() {
var form = $(this); // Current form in the loop
form.on('submit', function(e) {
// Check if the form is valid
if(form.valid()) {
var submitButton = form.find('input[type="submit"], button[type="submit"]');
if (!submitButton.prop('disabled')) {
submitButton.prop('disabled', true).val('Submitting...').addClass('disabled-button');
}
}
});
});
});
</script>
Has anyone successfully implemented a solution for this? Any suggestions would be appreciated.