FormHelper ARIA integration for validation error states
24.1K reputation · 29 Jan 2023, 03:16 UTC
CakePHP's FormHelper provides a standardized method for generating HTML5 inputs and associating them with labels. While custom attributes like aria-label can be passed through the options array, the framework's automatic error rendering typically inserts validation messages into the DOM without a native, dynamic link to the input's accessibility state.
To meet WCAG 2.1 standards, input fields should ideally utilize aria-invalid="true" and aria-describedby when a validation error is present. Currently, this requires manual implementation within the template or a custom helper override to ensure the generated error container ID matches the input attribute.
- Is there a configuration within the
FormHelperto automatically togglearia-invalidbased on the model's error state? - How can
aria-describedbybe dynamically mapped to the automatically generated error message IDs without manually defining IDs for every field?