diff --git a/assets/packages/limesurvey/survey.js b/assets/packages/limesurvey/survey.js index d232424c530..fba5f0db08b 100644 --- a/assets/packages/limesurvey/survey.js +++ b/assets/packages/limesurvey/survey.js @@ -404,4 +404,28 @@ function resetQuestionTimers(sid) { window.localStorage.removeItem('limesurvey_timers_' + timersessionname); }); window.localStorage.removeItem(surveyTimersItemName); -} \ No newline at end of file +} + +/** + * Disable submit button to prevent multiple submits + * This is done on 'document' instead of the '#limesurvey' form in order to allow + * other scripts (custom themes?) to cancel the submit before we disable the button. + */ + $(document).on('submit', function (e) { + // If the target is not the '#limesurvey' form, don't do anything. + if (e.target.id != 'limesurvey') { + return; + } + // We only care about the final submit, not normal forward/backward navigation. + var submitter = $(e.originalEvent.submitter); + if (submitter.attr('value') != 'movesubmit') { + return; + } + // Still, we disable all submit buttons to make sure the "back" button is not + // pressed while submitting. + $('#limesurvey button[type="submit"]').prop('disabled', true); + + // We also add a hidden input with the button's value, because it's not included + // in the request when the button is disabled. + $('#limesurvey').append(''); +}); \ No newline at end of file