Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions survey_question_type_five_star/static/src/js/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
},
});
});