From 226ed6001d1a66350dd4b87d61664dd59cd2c2a6 Mon Sep 17 00:00:00 2001 From: amdi-odoo Date: Fri, 24 Feb 2023 11:05:05 +0000 Subject: [PATCH] [IMP] survey: add matrix visual help MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Purpose ======= In addition to the current alert message, when a user forgot to pick an answer in a matrix, highlight in red the rows where the answer is missing. Task-3162051 closes odoo/odoo#111715 Signed-off-by: Warnon Aurélien (awa) --- addons/survey/static/src/js/survey_form.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js index 463718480c0..a25a4d964e6 100644 --- a/addons/survey/static/src/js/survey_form.js +++ b/addons/survey/static/src/js/survey_form.js @@ -724,10 +724,13 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend(SurveyPreloa break; case 'matrix': if (questionRequired) { - var subQuestionsIds = $questionWrapper.find('table').data('subQuestions'); - subQuestionsIds.forEach(function (id) { - if (!((questionId + '_' + id) in data)) { + const subQuestionsIds = $questionWrapper.find('table').data('subQuestions'); + // Highlight unanswered rows' header + const questionBodySelector = `div[id="${questionId}"] > .o_survey_question_matrix > tbody`; + subQuestionsIds.forEach((subQuestionId) => { + if (!(`${questionId}_${subQuestionId}` in data)) { errors[questionId] = constrErrorMsg; + self.el.querySelector(`${questionBodySelector} > tr[id="${subQuestionId}"] > th`).classList.add('bg-danger'); } }); } @@ -1196,6 +1199,9 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend(SurveyPreloa _resetErrors: function () { this.$('.o_survey_question_error').empty().removeClass('slide_in'); this.$('.o_survey_error').addClass('d-none'); + this.el.querySelectorAll('.o_survey_question_matrix th.bg-danger').forEach((row) => { + row.classList.remove('bg-danger'); + }); }, });