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:
@@ -5,14 +5,15 @@
|
|||||||
`action_url`. Included with `modal_id`, `title`, `form`, `action_url`, `submit_label`
|
`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
|
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
|
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 %}
|
{% endcomment %}
|
||||||
{% trans "Save" as default_submit_label %}
|
{% trans "Save" as default_submit_label %}
|
||||||
<dialog id="{{ modal_id }}" class="modal">
|
<dialog id="{{ modal_id }}" class="modal">
|
||||||
<div class="modal-box">
|
<div class="modal-box">
|
||||||
<h3 class="text-lg font-bold">{{ title }}</h3>
|
<h3 class="text-lg font-bold">{{ title }}</h3>
|
||||||
{% if blurb %}<p class="py-2 text-sm opacity-70">{{ blurb }}</p>{% endif %}
|
{% 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 %}
|
{% csrf_token %}
|
||||||
{% include "controlpanel/_form_fields.html" %}
|
{% include "controlpanel/_form_fields.html" %}
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -92,6 +92,7 @@
|
|||||||
class="file-input w-full {% if size_modifier %}file-input-{{ size_modifier }}{% endif %}"
|
class="file-input w-full {% if size_modifier %}file-input-{{ size_modifier }}{% endif %}"
|
||||||
name="{{ field.html_name }}"
|
name="{{ field.html_name }}"
|
||||||
{% if field.field.widget.attrs.accept %}accept="{{ field.field.widget.attrs.accept }}"{% endif %}
|
{% if field.field.widget.attrs.accept %}accept="{{ field.field.widget.attrs.accept }}"{% endif %}
|
||||||
|
{% if field.field.widget.attrs.multiple %}multiple{% endif %}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{% if field.value %}
|
{% if field.value %}
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ def form_field(
|
|||||||
field_type = "checkbox"
|
field_type = "checkbox"
|
||||||
case "textarea" | "markdownx":
|
case "textarea" | "markdownx":
|
||||||
field_type = "textarea"
|
field_type = "textarea"
|
||||||
case "clearablefile":
|
case "clearablefile" | "multiplefile":
|
||||||
field_type = "file"
|
field_type = "file"
|
||||||
case "selectmultiple":
|
case "selectmultiple":
|
||||||
field_type = "select"
|
field_type = "select"
|
||||||
|
|||||||
Reference in New Issue
Block a user