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 Jacob Walls)

  • 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 Antoliny, 3 weeks ago

Triage Stage: UnreviewedAccepted

Thank you !

It might be better for the legend tag to be associated with the "from" box.

Last edited 3 weeks ago by Antoliny (previous) (diff)

comment:2 by Varun Kasyap Pentamaraju, 3 weeks ago

Owner: set to Varun Kasyap Pentamaraju
Status: newassigned

Willing to contribute

comment:3 by Varun Kasyap Pentamaraju, 3 weeks ago

Has patch: set

comment:4 by Jacob Walls, 3 weeks ago

Needs tests: set

comment:5 by Jacob Walls, 3 weeks ago

Description: modified (diff)

comment:6 by Jacob Walls, 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 Jacob Walls, 3 weeks ago

Component: contrib.adminForms
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):  
    188188        id_ = widget.attrs.get("id") or self.auto_id
    189189        if id_:
    190190            id_for_label = widget.id_for_label(id_)
    191             if id_for_label:
     191            if id_for_label and tag != "legend":
    192192                attrs = {**(attrs or {}), "for": id_for_label}
    193193            if self.field.required and hasattr(self.form, "required_css_class"):
    194194                attrs = attrs or {}

comment:8 by Varun Kasyap Pentamaraju, 3 weeks ago

Patch needs improvement: unset

1) removed the for attribute from legend
2) updated tests

comment:9 by Jacob Walls, 3 weeks ago

Triage Stage: AcceptedReady for checkin

comment:10 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

Resolution: fixed
Status: assignedclosed

In 0eec2a1:

Fixed #36724 -- Removed invalid "for" attribute on <legend> tags.

Note: See TracTickets for help on using tickets.
Back to Top