Skip to content

Commit 6e890e9

Browse files
authored
Merge pull request #3 from studio24/hotfix/aria-describedby-correction
hotfix/aria-describedby-correction
2 parents eefe170 + 28ffc60 commit 6e890e9

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

src/Resources/views/Form/accessible-forms.html.twig

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44
{# Custom block to list errors #}
55
{%- block form_error_summary -%}
66
{% if form is not valid %}
7-
<div id="site-aria-alert" role="alert">
8-
<div class="govuk-error-summary rnib-error-summary" data-module="govuk-error-summary">
9-
<h2 class="govuk-error-summary__title rnib-error-summary__title">
10-
There are {{ form_all_errors(form) | length }} problems with this request
11-
</h2>
12-
<div class="govuk-error-summary__body rnib-error-summary__body">
13-
<ul class="govuk-error-summary__list rnib-error-summary__list">
14-
{% for error in form_all_errors(form) %}
15-
<li><a href='#{{ error.id }}'>{{ error.message }}</a></li>
16-
{% endfor %}
17-
</ul>
7+
<div id="site-aria-alert" role="alert">
8+
<div class="govuk-error-summary rnib-error-summary" data-module="govuk-error-summary">
9+
<h2 class="govuk-error-summary__title rnib-error-summary__title">
10+
There are {{ form_all_errors(form) | length }} problems with this request
11+
</h2>
12+
<div class="govuk-error-summary__body rnib-error-summary__body">
13+
<ul class="govuk-error-summary__list rnib-error-summary__list">
14+
{% for error in form_all_errors(form) %}
15+
<li><a href='#{{ error.id }}'>{{ error.message }}</a></li>
16+
{% endfor %}
17+
</ul>
18+
</div>
1819
</div>
1920
</div>
20-
</div>
2121
{% endif %}
2222
{%- endblock form_error_summary -%}
2323

2424
{# Custom markup for field errors. Appears as error above each field #}
2525
{%- block form_errors -%}
2626
{%- if errors|length > 0 -%}
2727
{% for error in errors %}
28-
<span id="id_{{ id }}_error{{ loop.index }}" class="tbxforms-error-message">Error: {{ error.message }}</span>
28+
<span id="{{ id }}_error{{ loop.index }}" class="tbxforms-error-message">Error: {{ error.message }}</span>
2929
{% endfor %}
3030
{%- endif -%}
3131
{%- endblock form_errors -%}
@@ -74,7 +74,7 @@
7474
{% set label_attr = label_attr|merge({'class': 'tbxforms-label tbxforms-checkboxes__label'}) %}
7575

7676
<label{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
77-
{{- block('form_label_content') -}}
77+
{{- block('form_label_content') -}}
7878
</label>
7979
{%- endif -%}
8080
{% endblock %}
@@ -88,15 +88,15 @@
8888
{% set label_attr = label_attr|merge({'class': 'rnib-form-label rnib-form-label--option govuk-radios__label'}) %}
8989

9090
<label{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
91-
{{- block('form_label_content') -}}
91+
{{- block('form_label_content') -}}
9292
</label>
9393
{%- endif -%}
9494
{% endblock %}
9595

9696
{# Custom markup for field hints #}
9797
{% block form_help -%}
9898
{%- if help -%}
99-
<div id="id_{{ id }}_hint" class="rnib-form-hint">
99+
<div id="{{ id }}_help" class="rnib-form-hint">
100100
{{- block('form_help_content') -}}
101101
</div>
102102
{%- endif -%}
@@ -106,28 +106,28 @@
106106
{%- block form_row_render -%}
107107
<div{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
108108
{% if compound %}
109-
<fieldset class="tbxforms-fieldset">
110-
{% endif %}
111-
{{- form_label(form) -}}
112-
{{- form_help(form) -}}
113-
{{- form_errors(form) -}}
114-
{{- form_widget(form, widget_attr) -}}
115-
{% if compound %}
116-
</fieldset>
109+
<fieldset class="tbxforms-fieldset">
110+
{% endif %}
111+
{{- form_label(form) -}}
112+
{{- form_help(form) -}}
113+
{{- form_errors(form) -}}
114+
{{- form_widget(form, widget_attr) -}}
115+
{% if compound %}
116+
</fieldset>
117117
{% endif %}
118118
</div>
119119
{%- endblock form_row_render -%}
120120

121121
{# This is for single non-choice checkboxes (eg. Agree to Terms) #}
122122
{% block checkbox_row %}
123-
<div class="tbxforms-form-group">
124-
<div class="tbxforms-checkboxes">
125-
<div class="tbxforms-checkboxes__item">
126-
{{- form_widget(form, row_attr) -}}
127-
{{- form_label(form) -}}
123+
<div class="tbxforms-form-group">
124+
<div class="tbxforms-checkboxes">
125+
<div class="tbxforms-checkboxes__item">
126+
{{- form_widget(form, row_attr) -}}
127+
{{- form_label(form) -}}
128+
</div>
128129
</div>
129130
</div>
130-
</div>
131131
{% endblock checkbox_row %}
132132

133133
{# Add custom markup to checkbox / radio buttons in choice context #}
@@ -183,11 +183,13 @@
183183
</button>
184184
{%- endblock button_widget -%}
185185

186+
{# Add class to textareas #}
186187
{%- block textarea_widget -%}
187188
{% set attr = attr|merge({'class': 'tbxforms-input tbxforms-textarea'}) %}
188189
{{- parent() -}}
189190
{%- endblock textarea_widget -%}
190191

192+
{# Customise markup and classes for birthday field #}
191193
{% block birthday_widget %}
192194
{% if widget == 'single_text' %}
193195
{{- block('form_widget_simple') -}}
@@ -206,3 +208,12 @@
206208

207209
{% endif %}
208210
{% endblock birthday_widget %}
211+
212+
{# Remove the required attribute from the element (disable frontend validation) #}
213+
{%- block widget_attributes -%}
214+
id="{{ id }}" name="{{ full_name }}"
215+
{%- if disabled %} disabled="disabled"{% endif -%}
216+
{% set attr = attr|merge({'required': false}) %}
217+
{{ block('attributes') }}
218+
{%- endblock widget_attributes -%}
219+

0 commit comments

Comments
 (0)