[Django] #34426: Pass the BoundField instance to the Widget.render

3 views
Skip to first unread message

Django

unread,
Mar 21, 2023, 8:08:41 AM3/21/23
to django-...@googlegroups.com
#34426: Pass the BoundField instance to the Widget.render
--------------------------------------------+------------------------
Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 4.2
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 |
--------------------------------------------+------------------------
Django 4's form rendering API is nice, but lacking a important feature to
me: the `Widget` used to render a particular `Field` doesn't have any
access to the corresponding `BoundField`. This makes rendering the field,
label, potential error messages altogether as well as more more complex
structures — like fields with subfields, for instance — impossible to
render atomically within the widget. If you want to do that, you're forced
to go up to the `Form`'s template itself.

My opinion is that
[[https://docs.djangoproject.com/en/4.1/ref/forms/widgets/#django.forms.Widget.render|`Widget.render`]]
should be passed the corresponding `BoundField` instance.

This would, I think, have 2 benefits:

1. allow easier rendering of complex widgets like
[https://github.com/django/django/blob/main/django/forms/widgets.py#L585
ChoiceWidget] using an iteration on the
[https://github.com/django/django/blob/main/django/forms/boundfield.py#L59-L60
BoundField]
([https://docs.djangoproject.com/en/4.1/ref/forms/widgets/#radioselect
which is what's documented] and would allow unification with
[https://github.com/django/django/blob/main/django/forms/widgets.py#L616-L659
ChoiceWidget.options and ChoiceWidget.optgroups])

2. allow rendering together `Form` fields that are related since
`BoundField` has access to the parent `Form` (for instance a form with
three options: email, phone, and other, respectively related to an email
input, a phone input and a text input that are displayed below each).

P.S.: This is a feature request but I'm still opening a bug here since I
can't join the django-developers mailing-list without a Google account.

--
Ticket URL: <https://code.djangoproject.com/ticket/34426>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 21, 2023, 8:37:16 AM3/21/23
to django-...@googlegroups.com
#34426: Pass the BoundField instance to the Widget.render
----------------------------------+--------------------------------------

Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 4.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #33166 (see also #34077).

--
Ticket URL: <https://code.djangoproject.com/ticket/34426#comment:1>

Reply all
Reply to author
Forward
0 new messages