Files
survey-tools/survey_dropdown_choice/views/survey_templates.xml

111 lines
6.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!--
Inherit the standard "simple_choice" template:
- when display_dropdown is set on the question AND we are not in
read-only/print mode, render our dropdown variant instead
- otherwise keep the standard radio-button rendering untouched
-->
<template id="question_simple_choice_inherit"
inherit_id="survey.question_simple_choice"
name="Question: simple choice (dropdown variant)">
<xpath expr="//div[@data-question-type='simple_choice_radio']" position="before">
<t t-if="question.display_dropdown and not survey_form_readonly"
t-call="survey_dropdown_choice.question_simple_choice_dropdown"/>
</xpath>
<xpath expr="//div[@data-question-type='simple_choice_radio']" position="attributes">
<attribute name="t-if">not question.display_dropdown or survey_form_readonly</attribute>
</xpath>
</template>
<!--
Searchable dropdown variant.
Keeps `data-question-type="simple_choice_radio"` and a real <input
type="radio"> per option so that the existing survey_form.js
validation/serialization logic (_validateForm, _prepareSubmitChoices)
works without any change.
-->
<template id="question_simple_choice_dropdown" name="Question: simple choice (dropdown)">
<t t-set="answer_line" t-value="answer_lines.filtered(lambda line: line.suggested_answer_id)"/>
<t t-set="comment_line" t-value="answer_lines.filtered(lambda line: line.value_char_box)"/>
<t t-set="selected_label" t-value="answer_line.suggested_answer_id"/>
<div class="o_survey_answer_wrapper o_survey_form_choice o_survey_dropdown_choice position-relative"
t-att-data-name="question.id"
t-att-data-is-skipped-question="is_skipped_question or None"
data-question-type="simple_choice_radio">
<div class="o_survey_dropdown_search_wrapper position-relative">
<input type="text"
class="o_survey_dropdown_search form-control pe-5"
autocomplete="off"
t-att-placeholder="question.question_placeholder or 'Type to filter...'"
t-att-value="selected_label.value if selected_label else ''"/>
<i class="o_survey_dropdown_caret fa fa-chevron-down position-absolute end-0 top-50 translate-middle-y me-3 text-muted"
aria-hidden="true"/>
</div>
<div class="o_survey_dropdown_panel d-none mt-1 border rounded shadow-sm bg-white">
<ul class="o_survey_dropdown_options list-unstyled m-0 p-0">
<t t-foreach="question.suggested_answer_ids" t-as="label">
<t t-set="answer_selected" t-value="answer_line and answer_line.suggested_answer_id.id == label.id"/>
<li t-attf-class="o_survey_dropdown_option px-3 py-2 #{'o_survey_selected bg-light' if answer_selected else ''}"
t-att-data-label-value="label.value"
t-att-data-answer-id="label.id">
<label t-att-for="str(question.id) + '_' + str(label.id)"
class="o_survey_choice_btn w-100 m-0 d-flex align-items-center"
style="cursor: pointer;">
<input t-att-id="str(question.id) + '_' + str(label.id)"
type="radio"
t-att-value="label.id"
t-attf-class="o_survey_form_choice_item invisible position-absolute #{'o_survey_form_choice_item_selected' if answer_selected else ''}"
t-att-name="question.id"
t-att-checked="'checked' if answer_selected else None"/>
<i t-attf-class="o_survey_dropdown_check fa fa-check me-2 #{'' if answer_selected else 'invisible'}"
aria-hidden="true"/>
<span class="text-break" t-field="label.value"/>
</label>
</li>
</t>
<li class="o_survey_dropdown_no_match d-none px-3 py-2 text-muted fst-italic">
No match found.
</li>
<t t-if="question.comments_allowed and question.comment_count_as_answer">
<li t-attf-class="o_survey_dropdown_option o_survey_dropdown_option_other px-3 py-2 #{'o_survey_selected bg-light' if comment_line else ''}"
data-label-value="">
<label class="o_survey_choice_btn w-100 m-0 d-flex align-items-center"
style="cursor: pointer;">
<input type="radio"
class="o_survey_form_choice_item o_survey_js_form_other_comment invisible position-absolute"
value="-1"
t-att-name="question.id"
t-att-checked="comment_line and 'checked' or None"/>
<i t-attf-class="o_survey_dropdown_check fa fa-check me-2 #{'' if comment_line else 'invisible'}"
aria-hidden="true"/>
<span t-out="question.comments_message or default_comments_message"/>
</label>
</li>
</t>
</ul>
</div>
<t t-if="question.comments_allowed and question.comment_count_as_answer">
<div t-attf-class="o_survey_comment_container mt-3 py-0 px-1 h-auto #{'d-none' if not comment_line else ''}">
<textarea type="text" class="form-control o_survey_question_text_box bg-transparent rounded-0 p-0"
t-att-disabled="None if comment_line else 'disabled'"><t t-esc="comment_line.value_char_box if comment_line else ''"/></textarea>
</div>
</t>
<div t-if="question.comments_allowed and not question.comment_count_as_answer"
class="mb-2 o_survey_comment_container mt-3">
<textarea type="text"
class="col form-control o_survey_comment o_survey_question_text_box bg-transparent rounded-0 p-0"
t-att-placeholder="question.comments_message or default_comments_message"><t t-esc="comment_line.value_char_box if comment_line else ''"/></textarea>
</div>
</div>
</template>
</odoo>