Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/FieldTypes/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class Html extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'mapped' => false,
'html' => null,
'view' => null
'view' => null,
]);
}

Expand Down
47 changes: 27 additions & 20 deletions src/Resources/views/Form/accessible-forms.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,19 @@
{# Adjust order of elements in form row, add fieldset for compound groups #}
{%- block form_row_render -%}
<div{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
{% if compound %}
<fieldset class="tbxforms-fieldset">
{% endif %}
{{- form_label(form) -}}
{{- form_help(form) -}}
{{- form_errors(form) -}}
{{- form_widget(form, widget_attr) -}}
{% if compound %}
</fieldset>
{% endif %}
{{- form_label(form) -}}
{{- form_help(form) -}}
{{- form_errors(form) -}}
{{- form_widget(form, widget_attr) -}}
</div>
{%- endblock form_row_render -%}

{# This is for single non-choice checkboxes (eg. Agree to Terms) #}
{% block checkbox_row %}
<div class="tbxforms-form-group">
<div class="tbxforms-form-group{% if errors %} tbxforms-form-group--error{% endif %}">
{%- if errors -%}
<span class="tbxforms-error-message">{{ errors }}</span>
{%- endif -%}
<div class="tbxforms-checkboxes">
<div class="tbxforms-checkboxes__item">
{{- form_widget(form, row_attr) -}}
Expand All @@ -136,16 +133,26 @@

{# Add custom markup to checkbox / radio buttons in choice context #}
{%- block choice_widget_expanded -%}
<div {{ block('widget_container_attributes') }}>
<div class="{% if multiple %}tbxforms-checkboxes{% else %}govuk-radios{% endif %}">
{%- for child in form %}
<div class="{% if multiple %}tbxforms-checkboxes__item{% else %}govuk-radios__item{% endif %}">
{{- form_widget(child) -}}
{{- form_label(child, null, {translation_domain: choice_translation_domain}) -}}
</div>
{% endfor -%}
</div>
{% if compound %}
<fieldset class="tbxforms-fieldset" {{ block('widget_container_attributes') }}>
{% else %}
<div {{ block('widget_container_attributes') }}>
{% endif %}

<div class="{% if multiple %}tbxforms-checkboxes{% else %}govuk-radios{% endif %}">
{%- for child in form %}
<div class="{% if multiple %}tbxforms-checkboxes__item{% else %}govuk-radios__item{% endif %}">
{{- form_widget(child) -}}
{{- form_label(child, null, {translation_domain: choice_translation_domain}) -}}
</div>
{% endfor -%}
</div>

{% if compound %}
</fieldset>
{% else %}
</div>
{% endif %}
{%- endblock choice_widget_expanded -%}

{# Add class to checkboxes #}
Expand Down
25 changes: 20 additions & 5 deletions src/Twig/AccessibleFormsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading