Skip to content

Commit 3381cdf

Browse files
committed
bug #26325 [Form][WCAG] Add hidden labels on date and time fields (Nyholm)
This PR was squashed before being merged into the 3.4 branch (closes #26325). Discussion ---------- [Form][WCAG] Add hidden labels on date and time fields | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | | License | MIT | Doc PR | According to my friend and WCAG2 expect [Sandra](https://twitter.com/sandrability): > "Guidance texts" (my translation) on DateType and DateTimeType etc are missing. It is great that they are grouped with a "fieldset" but it will be more clear if there was a label on each select. Especially since different countries have different time and date formats. The time form is read like "00 00" and you have no idea if it is seconds, minutes or hours. You may do "guidance texts" visually hidden if you do not want to change the looks of the form. But since "month" is shorten to "Jan" instead of "January" you may want to have clear and visual guidance texts. Commits ------- 14978e905c [Form][WCAG] Add hidden labels on date and time fields
2 parents b7b4665 + 7cd3a80 commit 3381cdf

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Resources/views/Form/bootstrap_base_layout.html.twig

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
<div {{ block('widget_container_attributes') }}>
4141
{{- form_errors(form.date) -}}
4242
{{- form_errors(form.time) -}}
43+
44+
<div class="sr-only">
45+
{%- if form.date.year is defined %}{{ form_label(form.date.year) }}{% endif -%}
46+
{%- if form.date.month is defined %}{{ form_label(form.date.month) }}{% endif -%}
47+
{%- if form.date.day is defined %}{{ form_label(form.date.day) }}{% endif -%}
48+
{%- if form.time.hour is defined %}{{ form_label(form.time.hour) }}{% endif -%}
49+
{%- if form.time.minute is defined %}{{ form_label(form.time.minute) }}{% endif -%}
50+
{%- if form.time.second is defined %}{{ form_label(form.time.second) }}{% endif -%}
51+
</div>
52+
4353
{{- form_widget(form.date, { datetime: true } ) -}}
4454
{{- form_widget(form.time, { datetime: true } ) -}}
4555
</div>
@@ -54,6 +64,12 @@
5464
{%- if datetime is not defined or not datetime -%}
5565
<div {{ block('widget_container_attributes') -}}>
5666
{%- endif %}
67+
<div class="sr-only">
68+
{{ form_label(form.year) }}
69+
{{ form_label(form.month) }}
70+
{{ form_label(form.day) }}
71+
</div>
72+
5773
{{- date_pattern|replace({
5874
'{{ year }}': form_widget(form.year),
5975
'{{ month }}': form_widget(form.month),
@@ -73,7 +89,10 @@
7389
{%- if datetime is not defined or false == datetime -%}
7490
<div {{ block('widget_container_attributes') -}}>
7591
{%- endif -%}
76-
{{- form_widget(form.hour) }}{% if with_minutes %}:{{ form_widget(form.minute) }}{% endif %}{% if with_seconds %}:{{ form_widget(form.second) }}{% endif %}
92+
<div class="sr-only">{{ form_label(form.hour) }}</div>
93+
{{- form_widget(form.hour) -}}
94+
{%- if with_minutes -%}:<div class="sr-only">{{ form_label(form.minute) }}</div>{{ form_widget(form.minute) }}{%- endif -%}
95+
{%- if with_seconds -%}:<div class="sr-only">{{ form_label(form.second) }}</div>{{ form_widget(form.second) }}{%- endif -%}
7796
{%- if datetime is not defined or false == datetime -%}
7897
</div>
7998
{%- endif -%}

0 commit comments

Comments
 (0)