From db13700829717992614d1fb199ed10f5f28825f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adasat=20Torres=20de=20Le=C3=B3n?= Date: Fri, 11 Jul 2025 10:16:27 +0100 Subject: [PATCH] [FIX] survey_question_type_five_star: Add validation on frontend. --- .../static/src/js/survey.js | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/survey_question_type_five_star/static/src/js/survey.js b/survey_question_type_five_star/static/src/js/survey.js index 145368a1..79af4a75 100644 --- a/survey_question_type_five_star/static/src/js/survey.js +++ b/survey_question_type_five_star/static/src/js/survey.js @@ -22,8 +22,6 @@ odoo.define("survey_question_type_five_star.survey", function (require) { .removeClass("fa-star-o"); var $input = $(target).parent().find("input"); $input.val(value); - // We will trigger the change in order to make it compatible with conditional. - // If it is not installed, it has no effects $input.trigger("change"); }, _prepareSubmitValues: function (formData, params) { @@ -36,5 +34,47 @@ odoo.define("survey_question_type_five_star.survey", function (require) { } }); }, + + _validateForm: function ($form, formData) { + var errors = {}; + this._resetErrors(); + var data = {}; + formData.forEach(function (value, key) { + data[key] = value; + }); + + var inactiveQuestionIds = this.options.sessionInProgress + ? [] + : this._getInactiveConditionalQuestionIds(); + + $form.find("[data-question-type]").each(function () { + var $input = $(this); + var $questionWrapper = $input.closest(".js_question-wrapper"); + var questionId = $questionWrapper.attr("id"); + + // If question is inactive, skip validation. + if (inactiveQuestionIds.includes(parseInt(questionId))) { + return; + } + + var questionRequired = $questionWrapper.data("required"); + var constrErrorMsg = $questionWrapper.data("constrErrorMsg"); + var validationErrorMsg = $questionWrapper.data("validationErrorMsg"); + + switch ($input.data("questionType")) { + case "star_rate": + if (questionRequired && !$input.val()) { + errors[questionId] = constrErrorMsg || validationErrorMsg; + } + break; + } + }); + + if (_.keys(errors).length > 0) { + this._showErrors(errors); + return false; + } + return this._super.apply(this, arguments); + }, }); });