#32340: Usability issues with Django form fields expecting specific patterns
-------------------------------------+-------------------------------------
Reporter: Thibaud | Owner: nobody
Colas |
Type: | Status: new
Uncategorized |
Component: Forms | Version: master
Severity: Normal | Keywords: accessibility,
Triage Stage: | usability, forms
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
-------------------------------------+-------------------------------------
Related: [https://code.djangoproject.com/ticket/32338 #32338],
[https://code.djangoproject.com/ticket/32339 #32339].
- Test form I’m basing this report on: http://django-admin-
tests.herokuapp.com/forms/example_form/p/
- Form fields definitions:
https://github.com/thibaudcolas/django_admin_tests/blob/main/django_admin_tests/forms.py
- Template:
https://github.com/thibaudcolas/django_admin_tests/blob/main/django_admin_tests/templates/django_admin_tests/example_form.html
Django offers a lot of fields that expect specific formats:
- Date and time fields – DateField, DatetimeField, TimeField,
SplitDateTimeField, DurationField
- More technical fields which have very specific formats: SlugField,
JSONField, UUIDField, RegexField, GenericIPAddressField
The default widget markup for all of those fields never displays the
expected format. For some fields this can somewhat be addressed via the
field’s label or help text (for example having "JSON" in the label, or a
description of a regex pattern in help text). But not for all. This is
particularly problematic for date and time fields:
- Even though end users know about date formats, just saying a field
expects a "Date" is never enough to know which specific format is
expected.
- Django supports providing supported formats globally via settings, and
at the field level. Ideally the widget would display the format(s) it’s
accepting based on this configuration, rather than having to hard-code it
in help text, which is prone to being incorrect / falling out of date /
not being set.
- The default error messages for invalid formats are vague ("Enter a valid
date.", "Enter a valid date/time.", "Enter a valid duration.").
I don’t think this is something that can necessarily be solved for all
cases directly in Django, but thought it would be worth raising
nonetheless. As-is, having default templates for those widgets makes it
easy for developers to overlook the need for this guidance. And we end up
with forms that are impossible to fill.
Solutions I can think of are:
- Update documentation to at least express the need for communicating the
expected format to end users. Ideally have examples of communicating those
formats for specific field types.
- Find a way to auto-display the format alongside the help text for the
field.
- Update the error messages to actually display the expected formats,
rather than a basic "Enter a valid <field type>".
I hope this makes sense, even though again this isn’t as clear-cut as the
other forms issues I noticed.
--
Ticket URL: <https://code.djangoproject.com/ticket/32340>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/055.f535595c4113f46d1579380494d89e22%40djangoproject.com.