diff options
| author | David Beguin <dbe@odoo.com> | 2019-12-10 15:34:00 +0000 |
|---|---|---|
| committer | Aurélien Warnon <awa@odoo.com> | 2020-01-10 11:01:04 +0000 |
| commit | 792d71faf5dfcfd9a931a53a4f78692520d423c9 (patch) | |
| tree | 1d981eaa01ff25a3185deb0282a61e1c7e4bd138 /addons/survey/static | |
| parent | 26147efeab9bd37679c0202950c48bdb1c8ec04a (diff) | |
[REF] survey: remove display mode for simple choice questions
This commit prepares the complete redesign of survey.
Simple choice question type will only use the radio button display mode.
So the dropdown display mode is deleted.
Task ID: 2152223
PR #41453
Diffstat (limited to 'addons/survey/static')
| -rw-r--r-- | addons/survey/static/src/js/survey_form.js | 31 | ||||
| -rw-r--r-- | addons/survey/static/tests/tours/certification_failure.js | 18 | ||||
| -rw-r--r-- | addons/survey/static/tests/tours/certification_success.js | 18 | ||||
| -rw-r--r-- | addons/survey/static/tests/tours/survey.js | 6 | ||||
| -rw-r--r-- | addons/survey/static/tests/tours/survey_prefill.js | 10 |
5 files changed, 18 insertions, 65 deletions
diff --git a/addons/survey/static/src/js/survey_form.js b/addons/survey/static/src/js/survey_form.js index c28cbebf8ec..2c6b6a1d5d1 100644 --- a/addons/survey/static/src/js/survey_form.js +++ b/addons/survey/static/src/js/survey_form.js @@ -52,10 +52,6 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({ /* * Checks, if the 'other' choice is checked. Applies only if the comment count as answer. - * In case of dropdownlist: - * If not checked : Clear the comment textarea and hide it - * If checked : show the comment textarea and focus on it - * In case of radio buttons * If not checked : Clear the comment textarea and disable it * If checked : enable the comment textarea and focus on it * @@ -67,24 +63,12 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({ var $otherItem = $choiceItemGroup.find('.o_survey_js_form_other_comment'); var $commentInput = $choiceItemGroup.find('textarea[type="text"]'); - // Handle dropdownlist - var $dropdownlist = $choiceItemGroup.find('select'); - var isDropdown = $dropdownlist.length > 0; - - var isOtherSelected = (isDropdown && $dropdownlist.val() === $otherItem.val()) || $otherItem.prop('checked'); - - if (isOtherSelected || $commentInput.hasClass('o_survey_comment')) { - if (isDropdown) { - $commentInput.toggleClass('d-none', false); - } - if (isOtherSelected) { - $commentInput.enable(); + if ($otherItem.prop('checked') || $commentInput.hasClass('o_survey_comment')) { + $commentInput.enable(); + if ($otherItem.prop('checked')) { $commentInput.focus(); } } else { - if (isDropdown) { - $commentInput.toggleClass('d-none', true); - } $commentInput.val(''); $commentInput.enable(false); } @@ -188,12 +172,9 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({ case 'datetime': params = self._prepareSubmitDates(params, this.name, this.value, true); break; - case 'simple_choice_dropdown': - params = self._prepareSubmitChoices(params, $(this), $(this).data('name'), 'option:selected'); - break; case 'simple_choice_radio': case 'multiple_choice': - params = self._prepareSubmitChoices(params, $(this), $(this).data('name'), 'input:checked'); + params = self._prepareSubmitChoices(params, $(this), $(this).data('name')); break; case 'matrix': params = self._prepareSubmitAnswersMatrix(params, $(this)); @@ -219,9 +200,9 @@ publicWidget.registry.SurveyFormWidget = publicWidget.Widget.extend({ * If the answer is not the 'comment selection' (=Other), calls the _prepareSubmitAnswer method to add the answer to the params * If there is a comment linked to that question, calls the _prepareSubmitComment method to add the comment to the params */ - _prepareSubmitChoices: function(params, $parent, questionId, selector) { + _prepareSubmitChoices: function (params, $parent, questionId) { var self = this; - $parent.find(selector).each(function () { + $parent.find('input:checked').each(function () { if (this.value !== '-1') { params = self._prepareSubmitAnswer(params, questionId, this.value); } diff --git a/addons/survey/static/tests/tours/certification_failure.js b/addons/survey/static/tests/tours/certification_failure.js index 5b5fb1c9ea0..95d292afab2 100644 --- a/addons/survey/static/tests/tours/certification_failure.js +++ b/addons/survey/static/tests/tours/certification_failure.js @@ -13,8 +13,7 @@ var failSteps = [{ // Page-1 trigger: 'a.btn.btn-primary.btn-lg:contains("Start Certification")', }, { // Question: Do we sell Acoustic Bloc Screens? content: "Selecting answer 'No'", - trigger: 'div.js_question-wrapper:contains("Do we sell Acoustic Bloc Screens") select', - run: 'text No', + trigger: 'div.js_question-wrapper:contains("Do we sell Acoustic Bloc Screens") label:contains("No") input', }, { // Question: Select all the existing products content: "Ticking answer 'Fanta'", trigger: 'div.js_question-wrapper:contains("Select all the existing products") label:contains("Fanta") input' @@ -32,19 +31,14 @@ var failSteps = [{ // Page-1 trigger: 'div.js_question-wrapper:contains("Select all the available customizations for our Customizable Desk") label:contains("Height") input' }, { // Question: How many versions of the Corner Desk do we have? content: "Selecting answer '2'", - trigger: 'div.js_question-wrapper:contains("How many versions of the Corner Desk do we have") select', - run: 'text 2', + trigger: 'div.js_question-wrapper:contains("How many versions of the Corner Desk do we have") label:contains("2") input', }, { // Question: Do you think we have missing products in our catalog? (not rated) content: "Missing products", trigger: 'div.js_question-wrapper:contains("Do you think we have missing products in our catalog") textarea', run: "text I don't know products enough to be able to answer that", }, { // Page-2 Question: How much do we sell our Cable Management Box? content: "Selecting answer '80$'", - trigger: 'div.js_question-wrapper:contains("How much do we sell our Cable Management Box") select', - run: function () { - var $select = $('div.js_question-wrapper:contains("How much do we sell our Cable Management Box") select'); - $select.val($('option:contains("80$")').val()); - } + trigger: 'div.js_question-wrapper:contains("How much do we sell our Cable Management Box") label:contains("80$") input', }, { // Question: Select all the the products that sell for 100$ or more content: "Ticking answer 'Corner Desk Right Sit'", trigger: 'div.js_question-wrapper:contains("Select all the the products that sell for 100$ or more") label:contains("Corner Desk Right Sit") input' @@ -55,11 +49,7 @@ var failSteps = [{ // Page-1 content: "Ticking answer 'Office Chair Black'", trigger: 'div.js_question-wrapper:contains("Select all the the products that sell for 100$ or more") label:contains("Office Chair Black") input' }, { // Question: What do you think about our prices (not rated)? - trigger: 'div.js_question-wrapper:contains("What do you think about our prices") select', - run: function () { - var $select = $('div.js_question-wrapper:contains("What do you think about our prices") select'); - $select.val($('option:contains("Correctly priced")').val()); - } + trigger: 'div.js_question-wrapper:contains("What do you think about our prices") label:contains("Correctly priced") input', }, { content: "Finish Survey", trigger: 'button[type="submit"]', diff --git a/addons/survey/static/tests/tours/certification_success.js b/addons/survey/static/tests/tours/certification_success.js index 03d3a22a9d7..f371e375266 100644 --- a/addons/survey/static/tests/tours/certification_success.js +++ b/addons/survey/static/tests/tours/certification_success.js @@ -12,8 +12,7 @@ tour.register('test_certification_success', { trigger: 'a.btn.btn-primary.btn-lg:contains("Start Certification")', }, { // Question: Do we sell Acoustic Bloc Screens? content: "Selecting answer 'Yes'", - trigger: 'div.js_question-wrapper:contains("Do we sell Acoustic Bloc Screens") select', - run: 'text Yes', + trigger: 'div.js_question-wrapper:contains("Do we sell Acoustic Bloc Screens") label:contains("Yes") input', }, { // Question: Select all the existing products content: "Ticking answer 'Chair floor protection'", trigger: 'div.js_question-wrapper:contains("Select all the existing products") label:contains("Chair floor protection") input' @@ -31,19 +30,14 @@ tour.register('test_certification_success', { trigger: 'div.js_question-wrapper:contains("Select all the available customizations for our Customizable Desk") label:contains("Legs") input' }, { // Question: How many versions of the Corner Desk do we have? content: "Selecting answer '2'", - trigger: 'div.js_question-wrapper:contains("How many versions of the Corner Desk do we have") select', - run: 'text 2', + trigger: 'div.js_question-wrapper:contains("How many versions of the Corner Desk do we have") label:contains("2") input', }, { // Question: Do you think we have missing products in our catalog? (not rated) content: "Missing products", trigger: 'div.js_question-wrapper:contains("Do you think we have missing products in our catalog") textarea', run: "text I think we should make more versions of the customizable desk, it's such an amazing product!", }, { // Page-2 Question: How much do we sell our Cable Management Box? content: "Selecting answer '80$' (wrong one)", - trigger: 'div.js_question-wrapper:contains("How much do we sell our Cable Management Box") select', - run: function () { - var $select = $('div.js_question-wrapper:contains("How much do we sell our Cable Management Box") select'); - $select.val($('option:contains("80$")').val()); - } + trigger: 'div.js_question-wrapper:contains("How much do we sell our Cable Management Box") label:contains("80$") input', }, { // Question: Select all the the products that sell for 100$ or more content: "Ticking answer 'Corner Desk Right Sit'", trigger: 'div.js_question-wrapper:contains("Select all the the products that sell for 100$ or more") label:contains("Corner Desk Right Sit") input' @@ -55,11 +49,7 @@ tour.register('test_certification_success', { trigger: 'div.js_question-wrapper:contains("Select all the the products that sell for 100$ or more") label:contains("Large Desk") input' }, { // Question: What do you think about our prices (not rated)? content: "Selecting answer 'Underpriced'", - trigger: 'div.js_question-wrapper:contains("What do you think about our prices") select', - run: function () { - var $select = $('div.js_question-wrapper:contains("What do you think about our prices") select'); - $select.val($('option:contains("Underpriced")').val()); - } + trigger: 'div.js_question-wrapper:contains("What do you think about our prices") label:contains("Underpriced") input', }, { content: "Finish Survey", trigger: 'button[type="submit"]', diff --git a/addons/survey/static/tests/tours/survey.js b/addons/survey/static/tests/tours/survey.js index e4540fba1ab..16ec56dc543 100644 --- a/addons/survey/static/tests/tours/survey.js +++ b/addons/survey/static/tests/tours/survey.js @@ -21,11 +21,7 @@ tour.register('test_survey', { run: 'text 05/05/1980', }, { content: 'Answer How frequently do you buy products online', - trigger: 'div.js_question-wrapper:contains("How frequently do you buy products online") select', - run: function () { - var $select = $('div.js_question-wrapper:contains("How frequently do you buy products online") select'); - $select.val($('option:contains("Once a month")').val()); - } + trigger: 'div.js_question-wrapper:contains("How frequently do you buy products online") label:contains("Once a month") input', }, { content: 'Answer How many times did you order products on our website', trigger: 'div.js_question-wrapper:contains("How many times did you order products on our website") input', diff --git a/addons/survey/static/tests/tours/survey_prefill.js b/addons/survey/static/tests/tours/survey_prefill.js index d93f3d96210..2872e316cf9 100644 --- a/addons/survey/static/tests/tours/survey_prefill.js +++ b/addons/survey/static/tests/tours/survey_prefill.js @@ -16,11 +16,7 @@ tour.register('test_survey_prefill', { trigger: 'div.js_question-wrapper:contains("When is your date of birth ?") input', run: 'text 05/05/1980', }, { // Question: How frequently do you buy products online ? - trigger: 'div.js_question-wrapper:contains("How frequently do you buy products online ?") select', - run: function() { - var optionID = $('option:contains("Once a week")').val(); - $('div.js_question-wrapper:contains("How frequently do you buy products online ?") select').val(optionID); - }, + trigger: 'div.js_question-wrapper:contains("How frequently do you buy products online ?") label:contains("Once a week") input', }, { // Question: How many times did you order products on our website ? trigger: 'div.js_question-wrapper:contains("How many times did you order products on our website ?") input', run: 'text 42', @@ -80,8 +76,8 @@ tour.register('test_survey_prefill', { return; } - var $selectQ3 = $('div.js_question-wrapper:contains("How frequently do you buy products online ?") select'); - if ($selectQ3.val() !== $('option:contains("Once a week")').val()) { + var $inputQ3 = $('div.js_question-wrapper:contains("How frequently do you buy products online ?") label:contains("Once a week") input'); + if (!$inputQ3.is(':checked')) { return; } |
