Opened 3 years ago
Closed 13 months ago
#33166 closed New feature (wontfix)
Add "field" to the context when rendering widgets.
Reported by: | Jacob Rief | Owned by: | Jacob Rief |
---|---|---|---|
Component: | Forms | Version: | 4.0 |
Severity: | Normal | Keywords: | form, widget, context |
Cc: | David Smith, Sarah Boyce | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Unsure if this shall be a feature request, but I noticed that when rendering a field label, the template's rendering context additionally contains the field
- and the form
-object. If however, I render the widget itself, this information is not available inside the widget's template rendering context. Apart from this inconsistency, being able to access the field
- and/or the form
-object, when rendering a widget is really useful.
Example:
I would like to use the form
-attribute inside some <input …>
-widgets, so that each field can refer to its corresponding form. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-form for details. The form
-object itself provides a name, which is used as the <form id="…" …>
. Therefore each widget has to know their form's name. This information currently can not be determined inside the widget's template.
Change History (12)
comment:1 by , 3 years ago
comment:2 by , 3 years ago
Well, in case of the label rendering context, the form
-object is accessible through the field
. However, the widget rendering context doesn't offer the field
-object.
comment:3 by , 3 years ago
Cc: | added |
---|---|
Summary: | Missing context when rendering form widgets → Add "field" to the context when rendering widgets. |
Triage Stage: | Unreviewed → Accepted |
Type: | Cleanup/optimization → New feature |
Tentatively accepted, this will require passing field
to the Widget.render()
.
This is not strictly related with 456466d932830b096d39806e291fe23ec5ed38d5.
comment:4 by , 3 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Here is a draft pull request to implement this:
https://github.com/django/django/pull/14955
comment:5 by , 3 years ago
Patch needs improvement: | set |
---|
comment:6 by , 3 years ago
I wonder about creating a circular context here. A field has a widget and you can access the field from the context of the widget and so on. See #33134 for a recent bug with field labels.
comment:8 by , 22 months ago
Cc: | added |
---|
comment:9 by , 22 months ago
As per David's comment on the PR here, we should resolve #34077 first, to see if that gives everything needed here.
comment:10 by , 22 months ago
Patch needs improvement: | set |
---|
Marking as "Patch needs improvement" as this is waiting for #34077.
comment:11 by , 19 months ago
Jacob, Have you seen cad376f844c7bdeeee7607a7c0ea8ae52061309b? Do we still need this change?
comment:12 by , 13 months ago
Has patch: | unset |
---|---|
Patch needs improvement: | unset |
Resolution: | → wontfix |
Status: | assigned → closed |
Triage Stage: | Accepted → Unreviewed |
I think it's no longer needed after cad376f844c7bdeeee7607a7c0ea8ae52061309b.
Note that
form
is no longer in the context after #33134.