From 8082779b1dad128da066248be21bc7e2221a6e79 Mon Sep 17 00:00:00 2001 From: Gabriel Jenik Date: Mon, 25 Apr 2022 14:20:55 -0300 Subject: [PATCH] Fixed issue #18026: Session expire message when submit button is clicked twice (#2353) --- assets/packages/limesurvey/survey.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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