[ADD] survey_dropdown_simple_choice
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m35s
tests / test (pull_request) Successful in 1m14s

Display "Multiple choice: only one answer" (simple_choice) survey
questions as a dropdown list instead of radio buttons, per question.

The native radios are kept (hidden by CSS) and still carry the answer:
the dropdown only clicks them, so validation, conditional questions,
"Other" comment, auto-submit and AJAX submit are handled natively.
In review / print mode, only the selected and correct answers are
displayed. Native rendering is kept when suggested answers contain
images.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 19:31:28 +02:00
parent 2835e2d2be
commit 9d55588f18
10 changed files with 242 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="survey_question_form_dropdown" model="ir.ui.view">
<field name="name">survey.question.form.dropdown</field>
<field name="model">survey.question</field>
<field name="inherit_id" ref="survey.survey_question_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='comments_allowed']" position="before">
<field name="display_dropdown" invisible="question_type != 'simple_choice'"/>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Add a dropdown on top of the native radios when the display_dropdown
flag is set. The radios are kept (hidden by CSS) and still carry the
answer: the dropdown only clicks them (see survey_form_dropdown.js).
In readonly mode (review / print), the radios are shown but only the
selected and correct answers are kept visible (data-survey-dropdown
"review"). The native rendering is kept when a suggestion carries an
image. -->
<template id="question_simple_choice" inherit_id="survey.question_simple_choice" name="Question: simple choice (dropdown)">
<xpath expr="//t[@t-set='comment_line']" position="after">
<t t-set="dropdown_enabled" t-value="question.display_dropdown and not any(a.value_image for a in question.suggested_answer_ids)"/>
<t t-set="use_dropdown" t-value="dropdown_enabled and not survey_form_readonly"/>
</xpath>
<xpath expr="//div[hasclass('o_survey_form_choice')]" position="attributes">
<attribute name="t-att-data-survey-dropdown">('review' if survey_form_readonly else 'edit') if dropdown_enabled else None</attribute>
</xpath>
<xpath expr="//t[@t-set='has_correct_answer']" position="after">
<div t-if="use_dropdown" class="col-sm-12 o_survey_dropdown_select">
<select class="form-select o_survey_dropdown_choice" t-att-aria-label="question.title">
<option value=""/>
<option t-foreach="question.suggested_answer_ids" t-as="label"
t-att-value="label.id"
t-att-selected="'selected' if answer_line.suggested_answer_id == label else None"
t-out="label.value"/>
<option t-if="question.comments_allowed and question.comment_count_as_answer" value="-1"
t-att-selected="'selected' if comment_line else None"
t-out="question.comments_message or default_comments_message"/>
</select>
</div>
</xpath>
</template>
</odoo>