Opened 3 weeks ago
Closed 3 weeks ago
#36724 closed Bug (fixed)
BoundField adds invalid "for" attribute on <legend> tags
| Reported by: | Jacob Walls | Owned by: | Varun Kasyap Pentamaraju |
|---|---|---|---|
| Component: | Forms | Version: | 6.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
- View the User model in the admin
- Inspect the label "Groups:"
<legend for="id_groups">Groups:</legend>
- Query for that element:
> document.getElementById("id_groups") null
There should probably be an id on the top <div> in this structure?
<div>
<div class="flex-container">
<div class="related-widget-wrapper" data-model-ref="group">
<div class="selector">
<div class="selector-available">
<div id="id_groups_from_title" class="selector-available-title">
...
SelectFilter2.js constructs ids like "id_groups_from_title" and "id_groups_selector_chosen" in this case.
Change History (10)
comment:1 by , 3 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:4 by , 3 weeks ago
| Needs tests: | set |
|---|
comment:5 by , 3 weeks ago
| Description: | modified (diff) |
|---|
comment:6 by , 3 weeks ago
Actually, the <legend> tag doesn't have a for attribute.
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/legend
comment:7 by , 3 weeks ago
| Component: | contrib.admin → Forms |
|---|---|
| Needs tests: | unset |
| Patch needs improvement: | set |
| Summary: | FilteredSelectMultiple widget has broken "for" attribute on <legend> → BoundField adds invalid "for" attribute on <legend> tags |
Reframing the issue to fix the 4.1 feature that added <legend> usage in BoundField (eba9a9b7f72995206af867600d6685b5405f172a) to remove the for attribute, something like:
-
django/forms/boundfield.py
diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index 39b0aaf97b..8e2f93f09b 100644
a b class BoundField(RenderableFieldMixin): 188 188 id_ = widget.attrs.get("id") or self.auto_id 189 189 if id_: 190 190 id_for_label = widget.id_for_label(id_) 191 if id_for_label :191 if id_for_label and tag != "legend": 192 192 attrs = {**(attrs or {}), "for": id_for_label} 193 193 if self.field.required and hasattr(self.form, "required_css_class"): 194 194 attrs = attrs or {}
comment:8 by , 3 weeks ago
| Patch needs improvement: | unset |
|---|
1) removed the for attribute from legend
2) updated tests
comment:9 by , 3 weeks ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Thank you !
Wouldn't it be better for the legend tag to be associated with the from box?