Opened 4 weeks ago

Closed 10 days ago

#28744 closed New feature (invalid)

enctype on <input> if FileField

Reported by: Thomas Güttler Owned by: nobody
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I think it would be feasible to add the attribute enctype to html input elements for FileFields.

Related docs: https://developer.mozilla.org/de/docs/Web/HTML/Element/Input#attr-formenctype

My use case: to be able to stop this useless dancing in admin:

grep -rsi 'has_file_field' .

./contrib/admin/options.py:            'has_file_field': True,  # FIXME - this should check if form or formsets have a FileField,


./contrib/admin/templates/admin/change_form.html:<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form" novalidate>{% csrf_token %}{% block form_top %}{% endblock %}



Change History (7)

comment:1 Changed 4 weeks ago by Claude Paroz

Component: UncategorizedForms
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature
Version: 1.11master

Indeed!

comment:2 Changed 4 weeks ago by Claude Paroz

Note: formenctype was supported from IE 10.

comment:3 Changed 4 weeks ago by Tim Graham

I didn't test, but I don't see anything to suggest that enctype works on <input type="file" ... />. From the page linked in the ticket description: "If the input element is a submit button or image, this attribute specifies the type of content that is used to submit the form to the server."

comment:4 Changed 4 weeks ago by Claude Paroz

Wrong hope? Thomas?

We could still fix the FIXME of contrib/admin/options.py, but that would have less appeal, of course.

comment:5 Changed 4 weeks ago by Tim Graham

There's #28585 to address the FIXME.

comment:6 Changed 10 days ago by Thomas Güttler

Just for the records, we use the enctype=“multipart/form-data” now unconditionally (meaning always, for all forms)

Before, I asked here:

https://stackoverflow.com/questions/46952608/why-not-use-enctype-multipart-form-data-always

We use this since some days in production and have seen no drawback up to now.

This means: one of several solutions would be to remove the "FIXME" comment in the django source :-)

comment:7 Changed 10 days ago by Tim Graham

Resolution: invalid
Status: newclosed

0cf00769ad11fa5ff0dff585d7f491a80f3e45ef is committed to address the FIXME. I don't think there's anything further to do for this ticket.

Note: See TracTickets for help on using tickets.
Back to Top