Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use aria-errormessage instead of aria-describedby for field error messages #2601

@MoritzLost

Description

@MoritzLost

Describe the bug

When a field has a validation error, Formie renders the <input> with aria-invalid, which is correct. It also displays an error message below the input and adds/updates the aria-describedby attribute of the <input> to point to the error message.

There are two problems with this:

  • The correct attribute to indicate the error message for an invalid input is aria-errormessage (MDN). Using this attribute allows screen readers to announce the message as an error, not as a generic description.
  • If the field also has regular instructions, aria-describedby is already used to relate the <input> to those instructions. Once the form is submitted, the aria-describedby attribute is updated to point to the error message, so the input loses its association to the instructions.

Using aria-errormessage to relate the <input> with the error message would solve both issues.

Steps to reproduce

  1. Create a form field with instructions and set it to required.
  2. Submit the form without filling out the field.

Form settings

  • Multi-page form: Either
  • Submission Method: Either
  • Client-side Validation: No
  • Custom Form Templates: No

Craft CMS version

5.8.18

Plugin version

3.1.4

Multi-site?

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions