[ADD] survey_dropdown_simple_choice
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:
33
survey_dropdown_simple_choice/views/survey_templates.xml
Normal file
33
survey_dropdown_simple_choice/views/survey_templates.xml
Normal 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>
|
||||
Reference in New Issue
Block a user