Re: [Django] #36582: Accessibility improvement for required field labels for inline forms in the admin.

6 views
Skip to first unread message

Django

unread,
Oct 16, 2025, 10:37:41 PM10/16/25
to django-...@googlegroups.com
#36582: Accessibility improvement for required field labels for inline forms in the
admin.
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: accessibility | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Antoliny):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/19970 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/36582#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 13, 2025, 7:17:02 PM11/13/25
to django-...@googlegroups.com
#36582: Accessibility improvement for required field labels for inline forms in the
admin.
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: accessibility | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Antoliny):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36582#comment:7>

Django

unread,
Dec 9, 2025, 3:21:52 AM12/9/25
to django-...@googlegroups.com
#36582: Accessibility improvement for required field labels for inline forms in the
admin.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: accessibility | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* stage: Accepted => Unreviewed

Comment:

I investigated why fields in admin inlines do not include the HTML
required attribute.

It turns out that inline forms in the admin are generated using Django’s
`modelformset_factory`. Forms created through formsets do not render the
required attribute on required fields.
{{{
# django/forms/formsets.py

class BaseFormSet(RenderableFormMixin):
...
def _construct_form(self, i, **kwargs):
"""Instantiate and return the i-th form instance in a formset."""
defaults = {
"auto_id": self.auto_id,
"prefix": self.add_prefix(i),
"error_class": self.error_class,
# Don't render the HTML 'required' attribute as it may cause
# incorrect validation for extra, optional, and deleted
# forms in the formset.
"use_required_attribute": False,
"renderer": self.form_renderer,
}
...
}}}

This behavior is also documented in the formset
[https://docs.djangoproject.com/en/6.0/topics/forms/formsets/#formset-
validation documentation].

So this doesn’t seem to be an issue specific to the admin, but rather a
broader accessibility concern with formsets.
Since form fields in formsets don’t include the required attribute, screen
reader users are unable to determine which fields are required in those
forms.

Should we consider adding another accessibility attribute to indicate
required fields for assistive technologies?

I’m reverting the ticket back to Unreviewed as it appears further triage
is needed :)
--
Ticket URL: <https://code.djangoproject.com/ticket/36582#comment:8>

Django

unread,
Dec 10, 2025, 11:46:55 AM12/10/25
to django-...@googlegroups.com
#36582: Accessibility improvement for required field labels for inline forms in the
admin.
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: accessibility | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Jacob Walls):

* stage: Unreviewed => Accepted

Comment:

Thanks for the analysis, Antoliny.

I think Sarah's triage in comment:5 is still right.

The undocumented `empty_permitted` parameter to `FormSet`—primarily used
in the admin for inlines (see ticket:16328#comment:2) but clearly in use
elsewhere (see #28171)—expresses a concept that cannot be statically
expressed with the HTML5 required attribute, since the semantic is more
like "usually required, but not in case all other fields are also empty".

> Should we consider adding another accessibility attribute to indicate
required fields for assistive technologies?

I think this would reduce to the same problem. "Required except sometimes
not".

I think Sarah is envisioning a change listener to remove/restore the
`required` attribute depending on whether any field in an inline is non-
empty.

Depending on how this is implemented, we might have to revisit the
exception added in #28171, since the following would no longer be invalid
usage: you can manage it with javascript:

{{{#!diff
diff --git a/django/contrib/admin/options.py
b/django/contrib/admin/options.py
index 6c202c8e61..983716205c 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -2294,6 +2294,7 @@ class ModelAdmin(BaseModelAdmin):
"instance": obj,
"prefix": prefix,
"queryset": inline.get_queryset(request),
+ "form_kwargs": { "empty_permitted": True,
"use_required_attribute": True },
}
if request.method == "POST":
formset_params.update(
}}}
Some details to work out there.
--
Ticket URL: <https://code.djangoproject.com/ticket/36582#comment:9>

Django

unread,
Dec 11, 2025, 3:58:04 AM12/11/25
to django-...@googlegroups.com
#36582: Accessibility improvement for required field labels for inline forms in the
admin.
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 5.2
Severity: Normal | Resolution:
Keywords: accessibility | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Antoliny):

Replying to [comment:9 Jacob Walls]:
Thank you, Jacob.
Your explanation was really helpful for me to understand this issue more
clearly!

It makes sense that cases like Admin inlines need `empty_permitted`(True)
and the `use_required_attribute`(True) attribute to coexist to some
extent.
And, as you said, we would rely on JavaScript to resolve the conflict
between these two behaviors.

As both of you mentioned, existing inline objects should keep their fields
marked as `required` by default, while fields for new inline forms should
dynamically add or remove the `required` attribute depending on whether
any data has been entered.

I think I finally understand the approach Sarah is suggesting.
If I’m still misunderstanding something, please feel free to point it out
— even if it’s a bit frustrating to explain again. (ㅠㅠ)
--
Ticket URL: <https://code.djangoproject.com/ticket/36582#comment:10>
Reply all
Reply to author
Forward
0 new messages