Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

[Django] #35881: MultiWidget bypasses subwidget rendering customization

9 views
Skip to first unread message

Django

unread,
Nov 2, 2024, 3:28:56 AM11/2/24
to django-...@googlegroups.com
#35881: MultiWidget bypasses subwidget rendering customization
------------------------------+--------------------------------------
Reporter: Adam Johnson | Type: Bug
Status: new | Component: Forms
Version: dev | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
[https://docs.djangoproject.com/en/stable/ref/forms/widgets/#django.forms.Widget.render
Widget.render] is documented as the place to override rendering behaviour,
with the top of `Widget` docs saying:

> You may also implement or override the render() method on custom
widgets.

On top of this, the
[https://docs.djangoproject.com/en/stable/ref/forms/renderers/#the-low-
level-render-api renderer API] is touted as another way to customize how
widgets are rendered.

`MultiWidget` bypasses both of these for its subwidgets. Rather than go
through their `render()` methods, it uses a template that just includes
the subwidget templates:

{{{
{% spaceless %}{% for widget in widget.subwidgets %}{% include
widget.template_name %}{% endfor %}{% endspaceless %}
}}}

I encountered this issue on a project with custom templates, where a
MultiValueField from a third-party package dropped the custom styles.

One solution could be to make a `MultiWidget.render()` method that calls
each subwidget's `render()` method and glues the results together.

Another would be to make the existing `MultiWidget.get_context` pass each
subwidget's render method into the context, and then the template could
call it.

One backwards compatibility concern is continuing to work if the user has
customized `multiwidget.html`, where they may be relying on the old
context data and using `{% include subwidget.template_name %}`.
--
Ticket URL: <https://code.djangoproject.com/ticket/35881>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 4, 2024, 3:17:19 AM11/4/24
to django-...@googlegroups.com
#35881: MultiWidget bypasses subwidget rendering customization
------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: Bug | Status: new
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Sarah Boyce):

* cc: David Smith (added)
* stage: Unreviewed => Accepted

Comment:

Thank you for the report Adam
--
Ticket URL: <https://code.djangoproject.com/ticket/35881#comment:1>

Django

unread,
Nov 22, 2024, 4:24:46 PM11/22/24
to django-...@googlegroups.com
#35881: MultiWidget bypasses subwidget rendering customization
------------------------------+--------------------------------------
Reporter: Adam Johnson | Owner: Alanna Cao
Type: Bug | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Alanna Cao):

* owner: (none) => Alanna Cao
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35881#comment:2>

Django

unread,
Dec 2, 2024, 3:44:40 PM12/2/24
to django-...@googlegroups.com
#35881: MultiWidget bypasses subwidget rendering customization
------------------------------+--------------------------------------
Reporter: Adam Johnson | Owner: Alanna Cao
Type: Bug | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Comment (by sschauk):

Hello! Could you please clarify in which file we can find the individual
render methods? Right now, I am looking at django/django/forms/widgets.py
where all the different render, render_js, and render_css functions are
but I don't think that's what you are referring to. I am also not quite
sure how the HTML code is linked to the multi widget function or current
sub widget functions. Any clarification would be very helpful!

(to clarify, I am collaborating with Alanna on this ticket)
--
Ticket URL: <https://code.djangoproject.com/ticket/35881#comment:3>

Django

unread,
Dec 3, 2024, 6:30:22 AM12/3/24
to django-...@googlegroups.com
#35881: MultiWidget bypasses subwidget rendering customization
------------------------------+--------------------------------------
Reporter: Adam Johnson | Owner: Alanna Cao
Type: Bug | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Comment (by Adam Johnson):

`MultiWidget` is in `django/forms/widgets.py`. Its `render()` method is
`Widget.render()` in the same file. That renders the template declared
within `MultiWidget.template_name` which is
`django/forms/widgets/multiwidget.html`. There are Django Template
Language and Jinja implementations of that template, but they both end up
using `{% include %}`, which is where the issue comes from.

Implementing a new `render()` within `MultiWidget` is one of the solutions
I proposed.
--
Ticket URL: <https://code.djangoproject.com/ticket/35881#comment:4>

Django

unread,
Dec 6, 2024, 6:45:15 PM12/6/24
to django-...@googlegroups.com
#35881: MultiWidget bypasses subwidget rendering customization
------------------------------+--------------------------------------
Reporter: Adam Johnson | Owner: Alanna Cao
Type: Bug | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Alanna Cao):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35881#comment:5>

Django

unread,
Dec 17, 2024, 10:09:26 AM12/17/24
to django-...@googlegroups.com
#35881: MultiWidget bypasses subwidget rendering customization
------------------------------+--------------------------------------
Reporter: Adam Johnson | Owner: Alanna Cao
Type: Bug | Status: assigned
Component: Forms | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35881#comment:6>
Reply all
Reply to author
Forward
0 new messages