From d271c320582309fff6579b5f533b14fbd7544d15 Mon Sep 17 00:00:00 2001 From: David Beguin Date: Thu, 23 Apr 2020 14:27:49 +0000 Subject: [PATCH] [FIX] survey: avoid autosubmit in session mode or when selecting other option In Session Mode: Before this commit, autosubmit was only dependant of the back button, but not of the session mode. In session mode, back button is ignored, and auto-submit sould not happen in session as user has not the possibility to go back in case he misclicked. After this commit, the auto-submit only happens if back button is activated AND if we are not in session mode. This is already checked inside survey._can_go_back method and already given to the template. When selecting 'other' option: For a single or multiple choice question, if the user is selecting the 'Other' choice, Auto submit should not happen. Otherwize, the user has not the possibility the type his custom answer. Also, if the question has comment that does not count as answer, the user should still be able to add a comment after having selected the answer. The comment can be a complement of answer. Task ID: 2230980 X-original-commit: 7f03380b49a55f3c2e36f379043c33a8a17f49ed --- addons/survey/static/src/js/survey_form.js | 6 ++++-- addons/survey/views/survey_templates.xml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js index ada2b644d32..661127221c8 100644 --- a/addons/survey/static/src/js/survey_form.js +++ b/addons/survey/static/src/js/survey_form.js @@ -204,9 +204,11 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({ } } } - // Submit Form + // Auto Submit Form var isLastQuestion = this.$('button[value="finish"]').length !== 0; - if (!isLastQuestion && this.options.usersCanGoBack && isQuestionComplete) { + var questionHasComment = $target.closest('.o_survey_form_choice').find('.o_survey_comment').length !== 0 + || $target.hasClass('o_survey_js_form_other_comment'); + if (!isLastQuestion && this.options.usersCanGoBack && isQuestionComplete && !questionHasComment) { this._submitForm({}); } } else { // $target.attr('type') === 'checkbox' diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index 6a595b581fc..cf76843f186 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -88,7 +88,7 @@ class="d-flex flex-grow-1 align-items-center" t-att-data-answer-token="answer.access_token" t-att-data-survey-token="survey.access_token" - t-att-data-users-can-go-back="survey.users_can_go_back" + t-att-data-users-can-go-back="survey.users_can_go_back and not answer.is_session_answer" t-att-data-session-in-progress="answer.is_session_answer" t-att-data-is-start-screen="answer.state == 'new'" t-att-data-readonly="survey_form_readonly"