Skip to content

Commit 0dabf77

Browse files
committed
Fix required checkboxes and radios to show required markers when required
1 parent b38c730 commit 0dabf77

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{#
2+
/**
3+
* @file
4+
* Default theme implementation for a fieldset element and its children.
5+
*
6+
* Available variables:
7+
* - attributes: HTML attributes for the <fieldset> element.
8+
* - errors: (optional) Any errors for this <fieldset> element, may not be set.
9+
* - required: Boolean indicating whether the <fieldset> element is required.
10+
* - legend: The <legend> element containing the following properties:
11+
* - title: Title of the <fieldset>, intended for use as the text
12+
of the <legend>.
13+
* - attributes: HTML attributes to apply to the <legend> element.
14+
* - description: The description element containing the following properties:
15+
* - content: The description content of the <fieldset>.
16+
* - attributes: HTML attributes to apply to the description container.
17+
* - description_display: Description display setting. It can have these values:
18+
* - before: The description is output before the element.
19+
* - after: The description is output after the element (default).
20+
* - invisible: The description is output after the element, hidden visually
21+
* but available to screen readers.
22+
* - children: The rendered child elements of the <fieldset>.
23+
* - prefix: The content to add before the <fieldset> children.
24+
* - suffix: The content to add after the <fieldset> children.
25+
*
26+
* @see template_preprocess_fieldset()
27+
*
28+
* @ingroup themeable
29+
*/
30+
#}
31+
{%
32+
set classes = [
33+
'js-form-item',
34+
'form-item',
35+
'js-form-wrapper',
36+
'form-wrapper',
37+
'chkbxrdio-grp',
38+
]
39+
%}
40+
<fieldset{{ attributes.addClass(classes) }}>
41+
{%
42+
set legend_span_classes = [
43+
'fieldset-legend',
44+
required ? 'js-form-required',
45+
required ? 'form-required',
46+
]
47+
%}
48+
{%
49+
set legend_classes = [
50+
required ? 'required',
51+
]
52+
%}
53+
{# Always wrap fieldset legends in a <span> for CSS positioning. #}
54+
<legend{{ legend.attributes.addClass(legend_classes) }}>
55+
<span{{ legend_span.attributes.addClass(legend_span_classes) }}>{{ legend.title }}</span>
56+
{% if required %}
57+
<strong class="required">({{ 'required'|t }})</strong>
58+
{% endif %}
59+
</legend>
60+
<div class="fieldset-wrapper">
61+
{% if description_display == 'before' and description.content %}
62+
<div{{ description.attributes.addClass('description') }}>{{ description.content }}</div>
63+
{% endif %}
64+
{% if errors %}
65+
<div>
66+
{{ errors }}
67+
</div>
68+
{% endif %}
69+
{% if prefix %}
70+
<span class="field-prefix">{{ prefix }}</span>
71+
{% endif %}
72+
{{ children }}
73+
{% if suffix %}
74+
<span class="field-suffix">{{ suffix }}</span>
75+
{% endif %}
76+
{% if description_display in ['after', 'invisible'] and description.content %}
77+
<div{{ description.attributes.addClass('description') }}>{{ description.content }}</div>
78+
{% endif %}
79+
</div>
80+
</fieldset>

0 commit comments

Comments
 (0)