Skip to content
Permalink
Browse files

[IMP] survey: auto submit for questions and matrix with simple choice

Purpose
=======

Speed up survey completion.

Specifications
==============

This commit apply an auto commit when user select a choice on a simple choice
question or on a matrix question with simple choice.

The auto commit happens following those conditions:
- Only on simple choice and matrix with simple choice questions
- For matrix, only when last subquestion is answered
- Only when Back mode is active
- If this is not the last question

Link
====

PR #46768
Task 2208574
  • Loading branch information
dbeguin authored and awa-odoo committed Mar 4, 2020
1 parent 0be55f7 commit 10abffc43cc4bf42d96b93d2221f3c6c612e1e14
Showing with 25 additions and 8 deletions.
  1. +19 −0 addons/survey/static/src/js/survey_form.js
  2. +6 −8 addons/survey/views/survey_templates.xml
@@ -111,6 +111,7 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
} else {
$choiceInput.prop("checked", !$choiceInput.prop("checked")).trigger('change');
}

// Avoid selection key to be typed into the textbox if 'other' is selected by key
event.preventDefault();
}
@@ -146,16 +147,28 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({

var $matrixBtn = $target.closest('.o_survey_matrix_btn');
if ($target.attr('type') === 'radio') {
var isQuestionComplete = false;
if ($matrixBtn.length > 0) {
$matrixBtn.closest('tr').find('td').removeClass('o_survey_selected');
$matrixBtn.addClass('o_survey_selected');
if (this.options.questionsLayout === 'page_per_question') {
var subQuestionsIds = $matrixBtn.closest('table').data('subQuestions');
var completedQuestions = [];
subQuestionsIds.forEach(function (id) {
if (self.$('tr#' + id).find('input:checked').length !== 0) {
completedQuestions.push(id);
}
});
isQuestionComplete = completedQuestions.length === subQuestionsIds.length;
}
} else {
var previouslySelectedAnswer = $choiceItemGroup.find('label.o_survey_selected');
previouslySelectedAnswer.removeClass('o_survey_selected');

var newlySelectedAnswer = $target.closest('label');
if (newlySelectedAnswer.find('input').val() !== previouslySelectedAnswer.find('input').val()) {
newlySelectedAnswer.addClass('o_survey_selected');
isQuestionComplete = this.options.questionsLayout === 'page_per_question';
}

// Conditional display
@@ -187,6 +200,12 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({
}
}
}
// Submit Form
var isLastQuestion = this.$('button[value="finish"]').length !== 0;
var isBackModeOn = $('.o_survey_navigation_submit[value="previous"]').length !== 0;
if (!isLastQuestion && isBackModeOn & isQuestionComplete) {
this._submitForm({});
}
} else { // $target.attr('type') === 'checkbox'
if ($matrixBtn.length > 0) {
$matrixBtn.toggleClass('o_survey_selected', !$matrixBtn.hasClass('o_survey_selected'));
@@ -186,7 +186,9 @@
<div class="row">
<div class="offset-3 col-6 text-center mt16">
<button type="submit" t-att-value="'next' if not survey_last else 'finish'" class="btn btn-primary">
Continue</button><span class="font-weight-bold text-muted ml-2 d-none d-md-inline"> or press Enter</span>
<t t-if="not survey_last">Continue</t>
<t t-else="">Submit</t>
</button><span class="font-weight-bold text-muted ml-2 d-none d-md-inline"> or press Enter</span>
</div>
</div>
</t>
@@ -220,12 +222,8 @@
<div class="row">
<div class="offset-3 col-6 text-center mt16">
<button type="submit" t-att-value="'next' if not survey_last else 'finish'" class="btn btn-primary">
<t t-if="answer.is_session_answer">
Submit
</t>
<t t-else="">
Continue
</t>
<t t-if="answer.is_session_answer or survey_last">Submit</t>
<t t-else="">Continue</t>
</button>
<span class="font-weight-bold text-muted ml-2 d-none d-md-inline">or press Enter</span>
</div>
@@ -527,7 +525,7 @@
</thead>
<tbody>
<t t-set="item_idx" t-value="0"/>
<tr class="bg-white text-white" t-foreach="question.matrix_row_ids" t-as="row_label">
<tr class="bg-white text-white" t-foreach="question.matrix_row_ids" t-as="row_label" t-att-id="row_label.id">
<th class="border-0 font-weight-normal text-left"><span t-field="row_label.value" /></th>
<t t-foreach="question.suggested_answer_ids" t-as="col_label">
<t t-set="answer" t-value="answer_lines.filtered(lambda line: line.suggested_answer_id == col_label and line.matrix_row_id == row_label)"/>

0 comments on commit 10abffc

Please sign in to comment.
You can’t perform that action at this time.