Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58676fc

Browse files
Nyholmnicolas-grekas
authored andcommitted
Make sure errors is a part of the label. This is a requirement for WCAG2.
We -could- work around this by using something like: <label for=”name”>Name: <span class=”hidden”>Error message</span></label> <input id=”name” type=”text”> <span aria-hidden=”true”>Error message</span>
1 parent 0f5e38c commit 58676fc

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ col-sm-2
2828
{{- form_label(form) -}}
2929
<div class="{{ block('form_group_class') }}">
3030
{{- form_widget(form) -}}
31-
{{- form_errors(form) -}}
3231
</div>
3332
{##}</div>
3433
{%- endif -%}
@@ -40,7 +39,6 @@ col-sm-2
4039
{{- form_label(form) -}}
4140
<div class="{{ block('form_group_class') }}">
4241
{{- form_widget(form) -}}
43-
{{- form_errors(form) -}}
4442
</div>
4543
</div>
4644
{##}</fieldset>

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,27 @@
7575
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-legend')|trim}) -%}
7676
{%- endif -%}
7777
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-control-label')|trim}) -%}
78-
{{- parent() -}}
79-
{%- endblock form_label %}
78+
79+
{% if label is not same as(false) -%}
80+
{% if not compound -%}
81+
{% set label_attr = label_attr|merge({'for': id}) %}
82+
{%- endif -%}
83+
{% if required -%}
84+
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
85+
{%- endif -%}
86+
{% if label is empty -%}
87+
{%- if label_format is not empty -%}
88+
{% set label = label_format|replace({
89+
'%name%': name,
90+
'%id%': id,
91+
}) %}
92+
{%- else -%}
93+
{% set label = name|humanize %}
94+
{%- endif -%}
95+
{%- endif -%}
96+
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{{- form_errors(form) -}}</{{ element|default('label') }}>
97+
{%- endif -%}
98+
{%- endblock form_label -%}
8099

81100
{% block checkbox_radio_label -%}
82101
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
@@ -113,7 +132,6 @@
113132
<{{ element|default('div') }} class="form-group">
114133
{{- form_label(form) -}}
115134
{{- form_widget(form) -}}
116-
{{- form_errors(form) -}}
117135
</{{ element|default('div') }}>
118136
{%- endblock form_row %}
119137

0 commit comments

Comments
 (0)