diff --git a/CHANGELOG.md b/CHANGELOG.md index d3bbfd9..466a24f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to accessible-forms will be documented in this file. +## [0.1.3](https://github.com/studio24/accessible-forms/compare/v0.1.3...v0.1.4) (2026-04-10) + +### Bug Fixes + +* Set mapped to false by default for custom Html block type, to prevent the need to do so manually. +* Moved choice fieldset element from form_row_render to choice_widget_expanded to allow checkbox attributes to be added to fieldset. (solves issue where screen readers were not announcing errors on checkbox/radio focus) +* Fixed multiple validation errors for one field being listed as one error and appended to the same string. +* Appended _0 to the error block so that the first checkbox/radio is highlighted when clicking the error summary anchor. + + ## [0.1.3](https://github.com/studio24/accessible-forms/compare/v0.1.2...v0.1.3) (2026-04-10) ### Bug Fixes diff --git a/src/FieldTypes/Html.php b/src/FieldTypes/Html.php index a930cc0..ff863c6 100644 --- a/src/FieldTypes/Html.php +++ b/src/FieldTypes/Html.php @@ -13,8 +13,9 @@ class Html extends AbstractType public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ + 'mapped' => false, 'html' => null, - 'view' => null + 'view' => null, ]); } diff --git a/src/Resources/views/Form/accessible-forms.html.twig b/src/Resources/views/Form/accessible-forms.html.twig index 2191d6e..402067b 100644 --- a/src/Resources/views/Form/accessible-forms.html.twig +++ b/src/Resources/views/Form/accessible-forms.html.twig @@ -109,22 +109,19 @@ {# Adjust order of elements in form row, add fieldset for compound groups #} {%- block form_row_render -%} - {% if compound %} -
- {% endif %} - {{- form_label(form) -}} - {{- form_help(form) -}} - {{- form_errors(form) -}} - {{- form_widget(form, widget_attr) -}} - {% if compound %} -
- {% endif %} + {{- form_label(form) -}} + {{- form_help(form) -}} + {{- form_errors(form) -}} + {{- form_widget(form, widget_attr) -}} {%- endblock form_row_render -%} {# This is for single non-choice checkboxes (eg. Agree to Terms) #} {% block checkbox_row %} -
+
+ {%- if errors -%} + {{ errors }} + {%- endif -%}
{{- form_widget(form, row_attr) -}} @@ -136,16 +133,26 @@ {# Add custom markup to checkbox / radio buttons in choice context #} {%- block choice_widget_expanded -%} -
-
- {%- for child in form %} -
- {{- form_widget(child) -}} - {{- form_label(child, null, {translation_domain: choice_translation_domain}) -}} -
- {% endfor -%} -
+ {% if compound %} +
+ {% else %} +
+ {% endif %} + +
+ {%- for child in form %} +
+ {{- form_widget(child) -}} + {{- form_label(child, null, {translation_domain: choice_translation_domain}) -}} +
+ {% endfor -%}
+ + {% if compound %} +
+ {% else %} +
+ {% endif %} {%- endblock choice_widget_expanded -%} {# Add class to checkboxes #} diff --git a/src/Twig/AccessibleFormsExtension.php b/src/Twig/AccessibleFormsExtension.php index 24add7b..f4aafbf 100644 --- a/src/Twig/AccessibleFormsExtension.php +++ b/src/Twig/AccessibleFormsExtension.php @@ -58,11 +58,26 @@ public function allErrors(FormView $form): array $errors = []; foreach ($form->children as $child) { if (isset($child->vars['errors']) && count($child->vars['errors']) > 0) { - $errors[] = [ - 'id' => $child->vars['id'], - 'name' => $child->vars['full_name'], - 'message' => (string) $child->vars['errors'] - ]; + + $id = $child->vars['id']; + + if (!empty($child->vars['choices']) && !empty($child->vars['expanded']) && $child->vars['expanded'] === true) { + $id .= '_0'; + } + + $fieldErrors = explode('ERROR: ', (string) $child->vars['errors']); + + foreach ($fieldErrors as $fieldError) { + if (!$fieldError) { + continue; + } + + $errors[] = [ + 'id' => $id, + 'name' => $child->vars['full_name'], + 'message' => 'Error: ' . $fieldError + ]; + } } } $form->vars['children_errors'] = $errors;