From 10725a31879c55ba8d92aaa3275093d136957bef Mon Sep 17 00:00:00 2001 From: Gregor Jerše Date: Fri, 2 Jun 2023 16:27:24 +0200 Subject: Fixed #32820 -- Added aria-invalid="true" to fields with errors. Co-authored-by: Demetris Stavrou Co-authored-by: David Smith --- docs/ref/forms/api.txt | 27 ++++++++++++++++++++++----- docs/ref/forms/fields.txt | 14 +++++++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'docs/ref/forms') diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 4d4f73d0b4..c4df99af7f 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -992,10 +992,20 @@ method you're using: ... } >>> f = ContactForm(data, auto_id=False) >>> print(f) -
Subject:
  • This field is required.
-
Message:
-
Sender:
  • Enter a valid email address.
-
Cc myself:
+
Subject: +
  • This field is required.
+ +
+
Message: + +
+
Sender: +
  • Enter a valid email address.
+ +
+
Cc myself: + +
.. _ref-forms-error-list-format: @@ -1154,7 +1164,7 @@ Attributes of ``BoundField`` >>> data = {"subject": "hi", "message": "", "sender": "", "cc_myself": ""} >>> f = ContactForm(data, auto_id=False) >>> print(f["message"]) - + >>> f["message"].errors ['This field is required.'] >>> print(f["message"].errors) @@ -1166,6 +1176,13 @@ Attributes of ``BoundField`` >>> str(f["subject"].errors) '' + When rendering a field with errors, ``aria-invalid="true"`` will be set on + the field's widget to indicate there is an error to screen reader users. + + .. versionchanged:: 5.0 + + The ``aria-invalid="true"`` was added when a field has errors. + .. attribute:: BoundField.field The form :class:`~django.forms.Field` instance from the form class that diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index dad5f1bbb8..307ebb15a2 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -196,9 +196,17 @@ and the HTML output will include any validation errors: >>> default_data = {"name": "Your name", "url": "http://"} >>> f = CommentForm(default_data, auto_id=False) >>> print(f) -
Name:
-
Url:
  • Enter a valid URL.
-
Comment:
  • This field is required.
+
Name: + +
+
Url: +
  • Enter a valid URL.
+ +
+
Comment: +
  • This field is required.
+ +
This is why ``initial`` values are only displayed for unbound forms. For bound forms, the HTML output will use the bound data. -- cgit v1.3