[IMP] survey_extra_fields : handle file question on page navigation

* Show a stored file (after navigating back) the same way as a freshly
  selected one: a "filename + Remove file" chip, input hidden until removal.
* Keep the stored file when a page is re-submitted without a new selection
  (instead of overwriting it with a skipped answer).
* "Remove file" now sends a sentinel to actually delete the stored file,
  so the removal persists across navigation.
This commit is contained in:
2026-06-10 17:23:31 +02:00
parent 9d1cd2746a
commit c940289d40
5 changed files with 146 additions and 14 deletions

View File

@@ -15,13 +15,26 @@
<template id="question_file" name="Question: File">
<div class="o_survey_comment_container p-0">
<t t-if="survey_form_readonly and answer_lines and answer_lines[0].value_file_fname">
<p><t t-out="answer_lines[0].value_file_fname"/></p>
<t t-set="existing_fname" t-value="answer_lines and answer_lines[0].value_file_fname"/>
<t t-if="survey_form_readonly">
<p t-if="existing_fname" class="mb-1">
<i class="fa fa-paperclip me-1"/><t t-out="answer_lines[0].value_file_fname"/>
</p>
</t>
<t t-if="not survey_form_readonly">
<t t-else="">
<!-- Uploaded file display, shown both for a fresh selection and when a
file was already stored server-side (e.g. navigating back). The raw
file input is hidden until the user clicks "Remove file". -->
<span t-attf-class="o_survey_file_selected d-inline-flex align-items-center #{'' if existing_fname else 'd-none'}">
<i class="fa fa-paperclip me-1"/>
<span class="o_survey_file_name"><t t-out="existing_fname or ''"/></span>
<button type="button" class="btn btn-link btn-sm text-danger o_survey_file_clear ms-2 py-0">
<i class="fa fa-times me-1"/>Remove file
</button>
</span>
<input
type="file"
class="o_survey_question_file"
t-attf-class="o_survey_question_file #{'d-none' if existing_fname else ''}"
t-att-name="question.id"
t-att-data-question-type="question.question_type"
t-att-accept="question.allowed_extensions or None"