Fix file uploads in modal forms: multi-file input rendering + enctype

Two bugs, both invisible until the news photo upload modal exercised
them: the shared field template didn't recognise a custom multi-file
widget (it fell through to a plain, useless text input), and the modal
form itself had no enctype="multipart/form-data" -- so even a correctly
rendered file input would have posted filenames only, never content.
This commit is contained in:
2026-08-03 21:37:04 +02:00
parent d9b4337319
commit 859e3e5f84
3 changed files with 5 additions and 3 deletions

View File

@@ -5,14 +5,15 @@
`action_url`. Included with `modal_id`, `title`, `form`, `action_url`, `submit_label`
and `submit_icon`, plus an optional `blurb`. The submit button sits outside the form
tag (linked via the `form` attribute) so it can share the `modal-action` row with the
dialog-closing Cancel button without nesting one <form> inside another.
dialog-closing Cancel button without nesting one <form> inside another. `enctype` is
always multipart -- harmless for a form with no file field, required for one that has.
{% endcomment %}
{% trans "Save" as default_submit_label %}
<dialog id="{{ modal_id }}" class="modal">
<div class="modal-box">
<h3 class="text-lg font-bold">{{ title }}</h3>
{% if blurb %}<p class="py-2 text-sm opacity-70">{{ blurb }}</p>{% endif %}
<form method="post" action="{{ action_url }}" id="{{ modal_id }}-form">
<form method="post" action="{{ action_url }}" id="{{ modal_id }}-form" enctype="multipart/form-data">
{% csrf_token %}
{% include "controlpanel/_form_fields.html" %}
</form>

View File

@@ -92,6 +92,7 @@
class="file-input w-full {% if size_modifier %}file-input-{{ size_modifier }}{% endif %}"
name="{{ field.html_name }}"
{% if field.field.widget.attrs.accept %}accept="{{ field.field.widget.attrs.accept }}"{% endif %}
{% if field.field.widget.attrs.multiple %}multiple{% endif %}
/>
{% if field.value %}