#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701870412428a-03e3752e-6a3b-4b5b-b805-51da33cefc56-000000%40eu-central-1.amazonses.com.