Skip to content

Commit 735bef8

Browse files
committed
Reworked checkbox/radio grouping, added support for single non-choice checkboxes.
Added classes to inputs and selects.
1 parent d1318d1 commit 735bef8

1 file changed

Lines changed: 50 additions & 16 deletions

File tree

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

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,30 @@
3535
{%- endblock form_start -%}
3636

3737
{%- block form_row -%}
38-
{% if expanded %}
39-
<fieldset class="tbxforms-fieldset">
40-
{% endif %}
4138
{% set row_attr = row_attr|merge({'class': 'tbxforms-form-group'}) %}
4239
{%- if errors|length > 0 -%}
4340
{% set class = row_attr.class ~ ' tbxforms-form-group--error' %}
4441
{% set row_attr = row_attr|merge({'class': class}) %}
4542
{%- endif -%}
4643
{{- parent() -}}
47-
{% if expanded %}
48-
</fieldset>
49-
{% endif %}
5044
{%- endblock form_row -%}
5145

5246
{# Field rows become fieldsets on checkbox and radio buttons, so make the label the legend #}
5347
{%- block form_label -%}
5448
{% if label is not same as(false) -%}
55-
{% if expanded %}
56-
<legend>{{- block('form_label_content') -}}</legend>
57-
{% else %}
49+
{%- if compound -%}
50+
<legend><h2 class="rnib-form-label__wrapper">{{- block('form_label_content') -}}</h2></legend>
51+
{%- else -%}
5852
{% if not compound -%}
5953
{% set label_attr = label_attr|merge({for: id}) %}
6054
{%- endif -%}
6155
{% set label_attr = label_attr|merge({'class': 'rnib-form-label'}) %}
6256
<h2 class="rnib-form-label__wrapper">
63-
<{{ element|default('label') }}{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
57+
<label{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
6458
{{- block('form_label_content') -}}
65-
</{{ element|default('label') }}>
59+
</label>
6660
</h2>
67-
{% endif %}
61+
{%- endif -%}
6862
{%- endif -%}
6963
{%- endblock form_label -%}
7064

@@ -75,9 +69,9 @@
7569
{%- endif -%}
7670
{% set label_attr = label_attr|merge({'class': 'tbxforms-label tbxforms-checkboxes__label'}) %}
7771

78-
<{{ element|default('label') }}{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
72+
<label{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
7973
{{- block('form_label_content') -}}
80-
</{{ element|default('label') }}>
74+
</label>
8175
{%- endif -%}
8276
{% endblock %}
8377

@@ -88,9 +82,9 @@
8882
{%- endif -%}
8983
{% set label_attr = label_attr|merge({'class': 'rnib-form-label rnib-form-label--option govuk-radios__label'}) %}
9084

91-
<{{ element|default('label') }}{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
85+
<label{% if label_attr %}{% with {attr: label_attr} %}{{ block('attributes') }}{% endwith %}{% endif %}>
9286
{{- block('form_label_content') -}}
93-
</{{ element|default('label') }}>
87+
</label>
9488
{%- endif -%}
9589
{% endblock %}
9690

@@ -105,13 +99,31 @@
10599
{# Adjust order of elements in form row #}
106100
{%- block form_row_render -%}
107101
<div{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
102+
{% if compound %}
103+
<fieldset class="tbxforms-fieldset">
104+
105+
{% endif %}
108106
{{- form_label(form) -}}
109107
{{- form_help(form) -}}
110108
{{- form_errors(form) -}}
111109
{{- form_widget(form, widget_attr) -}}
110+
{% if compound %}
111+
</fieldset>
112+
{% endif %}
112113
</div>
113114
{%- endblock form_row_render -%}
114115

116+
{% block checkbox_row %}
117+
<div class="tbxforms-form-group">
118+
<div class="tbxforms-checkboxes">
119+
<div class="tbxforms-checkboxes__item">
120+
{{- form_widget(form, row_attr) -}}
121+
{{- form_label(form) -}}
122+
</div>
123+
</div>
124+
</div>
125+
{% endblock checkbox_row %}
126+
115127
{# Checkbox / Radio buttons #}
116128
{%- block choice_widget_expanded -%}
117129
<div {{ block('widget_container_attributes') }}>
@@ -125,3 +137,25 @@
125137
</div>
126138
</div>
127139
{%- endblock choice_widget_expanded -%}
140+
141+
{%- block checkbox_widget -%}
142+
<input type="checkbox" class="tbxforms-checkboxes__input" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
143+
{%- endblock checkbox_widget -%}
144+
145+
{%- block radio_widget -%}
146+
<input type="radio" class="govuk-radios__input" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
147+
{%- endblock radio_widget -%}
148+
149+
{# Add classes to input elements #}
150+
{%- block form_widget_simple -%}
151+
{% set attr = attr|merge({'class': 'tbxforms-input'}) %}
152+
{%- if type == 'text' -%}
153+
{%- set attr = attr|merge({'class': 'tbxforms-input tbxforms-input--text'}) -%}
154+
{% endif %}
155+
{{- parent() -}}
156+
{%- endblock form_widget_simple -%}
157+
158+
{%- block choice_widget_collapsed -%}
159+
{% set attr = attr|merge({'class': 'tbxforms-select'}) %}
160+
{{- parent() -}}
161+
{%- endblock choice_widget_collapsed -%}

0 commit comments

Comments
 (0)