Opened 6 weeks ago

Closed 6 days ago

Last modified 5 days ago

#36949 closed Bug (fixed)

Missing label on each <select> in a fieldset

Reported by: Jacob Walls Owned by: David Smith
Component: contrib.admin Version: 6.0
Severity: Release blocker Keywords: accessibility, fieldset
Cc: Antoliny, David Smith 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

As Thibaud mentioned here when use_fieldset was added to forms, we're lacking a label on each <select> element in a <fieldset>, even though a <legend> is present for the fieldset.

Now that the admin uses Widget.use_fieldset since #35892, it's easy to reproduce by just checking a ForeignKey field in the admin:

Then, in Chrome Dev Tools, the lighthouse tab reports:

Select elements do not have associated label elements.

Pure forms reproducer, in a shell:

from django.db import models
from django import forms

class Person(models.Model):
    best_friend = models.ForeignKey(
        "auth.User",
        models.CASCADE,
    )
    class Meta:
        app_label = "myapp.Person"

class MyWidget(forms.Select):
    use_fieldset = True

class PersonForm(forms.ModelForm):
    class Meta:
        model = Person
        fields = ["best_friend"]
        widgets = {"best_friend": MyWidget}

print(PersonForm().as_p())
<p>
    <label for="id_best_friend">Best friend:</label>
    <select name="best_friend" required id="id_best_friend">
  <option value="" selected>---------</option>

  <option value="2">anonymous</option>

  <option value="1">admin</option>

</select>
    
    
      
    
  </p>

Tentatively assigning to Eli as a Djangonaut Space navigator to evaluate if a good fit for anyone.

Change History (14)

comment:1 by Jacob Walls, 6 weeks ago

There's some relevant advice in a related ticket: ticket:36509#comment:1

comment:2 by Natalia Bidart, 5 weeks ago

Cc: Eliana Rosselli added
Triage Stage: UnreviewedAccepted

Thank you!

comment:3 by Bhuvnesh Nama, 3 weeks ago

Submitted PR for review.

PR: https://github.com/django/django/pull/20933

comment:4 by Jacob Walls, 3 weeks ago

Cc: Eliana Rosselli removed
Has patch: set
Owner: changed from Eliana Rosselli to bhuvnesh-nama

comment:5 by Jacob Walls, 3 weeks ago

Cc: David Smith added
Needs tests: set
Patch needs improvement: set

comment:6 by Bhuvnesh Nama, 3 weeks ago

I've pushed updates to the pull request to address the review feedback, including adding tests and updating the implementation.

PR: https://github.com/django/django/pull/20933

comment:7 by Jacob Walls, 3 weeks ago

Needs tests: unset

comment:8 by Jacob Walls, 2 weeks ago

Component: Formscontrib.admin
Severity: NormalRelease blocker

David's helpful review revealed that it was a bug in 4187da258fe212d494cb578a0bc2b52c4979ab95 that self.use_fieldset = True was done naively on RelatedFieldWidgetWrapper in the admin, so elevating to release blocker and reclassifying to the admin.

comment:9 by Jacob Walls, 9 days ago

Owner: changed from bhuvnesh-nama to David Smith

comment:10 by Jacob Walls, 6 days ago

Cc: Thibaud Colas removed
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:11 by Jacob Walls <jacobtylerwalls@…>, 6 days ago

Resolution: fixed
Status: assignedclosed

In 253f552c:

Fixed #36949 -- Improved RelatedFieldWidgetWrapper <label>s.

Regression in 4187da258fe212d494cb578a0bc2b52c4979ab95.

comment:12 by Jacob Walls <jacobtylerwalls@…>, 6 days ago

In ea8e293f:

[6.0.x] Fixed #36949 -- Improved RelatedFieldWidgetWrapper <label>s.

Regression in 4187da258fe212d494cb578a0bc2b52c4979ab95.

Backport of 253f552c5809fa096116b601bd842ca4f3504860 from main.

comment:13 by Jacob Walls <jacobtylerwalls@…>, 5 days ago

In 123fa3a3:

Refs #36949 -- Removed hardcoded pks in modeladmin tests.

comment:14 by Jacob Walls <jacobtylerwalls@…>, 5 days ago

In ffc83c55:

[6.0.x] Refs #36949 -- Removed hardcoded pks in modeladmin tests.

Backport of 123fa3a3f38abdb73055acc9a2cbbe3537f9323a from main.

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