#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 , 6 weeks ago
comment:4 by , 3 weeks ago
| Cc: | removed |
|---|---|
| Has patch: | set |
| Owner: | changed from to |
comment:5 by , 3 weeks ago
| Cc: | added |
|---|---|
| Needs tests: | set |
| Patch needs improvement: | set |
comment:6 by , 3 weeks ago
I've pushed updates to the pull request to address the review feedback, including adding tests and updating the implementation.
comment:7 by , 3 weeks ago
| Needs tests: | unset |
|---|
comment:8 by , 2 weeks ago
| Component: | Forms → contrib.admin |
|---|---|
| Severity: | Normal → Release 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 , 9 days ago
| Owner: | changed from to |
|---|
comment:10 by , 6 days ago
| Cc: | removed |
|---|---|
| Patch needs improvement: | unset |
| Triage Stage: | Accepted → Ready for checkin |
There's some relevant advice in a related ticket: ticket:36509#comment:1