mirror of
https://github.com/django/django.git
synced 2025-11-18 11:00:24 +00:00
Fixed #35189 -- Improved admin collapsible fieldsets by using <details> elements.
This work improves the accessibility of the add and change pages in the admin site by adding <details> and <summary> elements to the collapsible fieldsets. This has the nice side effect of no longer requiring custom JavaScript helpers to implement the fieldsets' show/hide capabilities. Thanks to James Scholes for the accessibility advice, and to Sarah Boyce and Tom Carrick for reviews. Co-authored-by: Natalia <124304+nessita@users.noreply.github.com> Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
This commit is contained in:
parent
01ed59f753
commit
e4a693f50a
11 changed files with 119 additions and 88 deletions
|
|
@ -18,6 +18,7 @@ from django.db.models.fields.related import (
|
|||
from django.forms.utils import flatatt
|
||||
from django.template.defaultfilters import capfirst, linebreaksbr
|
||||
from django.urls import NoReverseMatch, reverse
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.html import conditional_escape, format_html
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext
|
||||
|
|
@ -116,10 +117,14 @@ class Fieldset:
|
|||
|
||||
@property
|
||||
def media(self):
|
||||
if "collapse" in self.classes:
|
||||
return forms.Media(js=["admin/js/collapse.js"])
|
||||
return forms.Media()
|
||||
|
||||
@cached_property
|
||||
def is_collapsible(self):
|
||||
if any([field in self.fields for field in self.form.errors]):
|
||||
return False
|
||||
return "collapse" in self.classes
|
||||
|
||||
def __iter__(self):
|
||||
for field in self.fields:
|
||||
yield Fieldline(
|
||||
|
|
@ -438,6 +443,12 @@ class InlineAdminFormSet:
|
|||
def forms(self):
|
||||
return self.formset.forms
|
||||
|
||||
@cached_property
|
||||
def is_collapsible(self):
|
||||
if any(self.formset.errors):
|
||||
return False
|
||||
return "collapse" in self.classes
|
||||
|
||||
def non_form_errors(self):
|
||||
return self.formset.non_form_errors()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue