#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]:
 > 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.

 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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019b0ca19e47-9404be58-e7dc-4ae8-b297-3e4607ce2bdf-000000%40eu-central-1.amazonses.com.

Reply via email to