-
Notifications
You must be signed in to change notification settings - Fork 329
/
template.njk
97 lines (93 loc) · 3.18 KB
/
template.njk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{% from "../error-message/macro.njk" import govukErrorMessage -%}
{% from "../fieldset/macro.njk" import govukFieldset %}
{% from "../hint/macro.njk" import govukHint %}
{% from "../input/macro.njk" import govukInput %}
{#- a record of other elements that we need to associate with the input using
aria-describedby – for example hints or error messages -#}
{% set describedBy = "" %}
{% if params.items %}
{% set dateInputItems = params.items %}
{% else %}
{% set dateInputItems = [
{
name: "day",
classes: "govuk-input--width-2"
},
{
name: "month",
classes: "govuk-input--width-2"
},
{
name: "year",
classes: "govuk-input--width-4"
}
] %}
{% endif %}
{#- Capture the HTML so we can optionally nest it in a fieldset -#}
{% set innerHtml %}
{% if params.hint %}
{% set hintId = params.id + "-hint" %}
{% set describedBy = describedBy + " " + hintId if describedBy else hintId %}
{{ govukHint({
id: hintId,
classes: params.hint.classes,
attributes: params.hint.attributes,
html: params.hint.html,
text: params.hint.text
}) | indent(2) | trim }}
{% endif %}
{% if params.errorMessage %}
{% set errorId = params.id + "-error" %}
{% set describedBy = describedBy + " " + errorId if describedBy else errorId %}
{{ govukErrorMessage({
id: errorId,
classes: params.errorMessage.classes,
attributes: params.errorMessage.attributes,
html: params.errorMessage.html,
text: params.errorMessage.text
}) | indent(2) | trim }}
{% endif %}
<div class="govuk-date-input {%- if params.classes %} {{ params.classes }}{% endif %}"
{%- for attribute, value in params.attributes %} {{attribute}}="{{value}}"{% endfor %}
{%- if params.id %} id="{{ params.id }}"{% endif %}>
{% for item in dateInputItems %}
<div class="govuk-date-input__item">
{{ govukInput({
label: {
text: item.label if item.label else item.name | capitalize,
classes: "govuk-date-input__label"
},
id: item.id if item.id else (params.id + "-" + item.name),
classes: "govuk-date-input__input " + (item.classes if item.classes),
name: (params.namePrefix + "-" + item.name) if params.namePrefix else item.name,
value: item.value,
type: "number",
autocomplete: item.autocomplete,
attributes: {
pattern: "[0-9]*"
}
}) | indent(6) | trim }}
</div>
{% endfor %}
</div>
{% endset %}
<div class="govuk-form-group {%- if params.errorMessage %} govuk-form-group--error{% endif %} {%- if params.formGroup.classes %} {{ params.formGroup.classes }}{% endif %}">
{% if params.fieldset %}
{#- We override the fieldset's role to 'group' because otherwise JAWS does not
announce the description for a fieldset comprised of text inputs, but
adding the role to the fieldset always makes the output overly verbose for
radio buttons or checkboxes. -#}
{% call govukFieldset({
describedBy: describedBy,
classes: params.fieldset.classes,
attributes: {
role: "group"
},
legend: params.fieldset.legend
}) %}
{{ innerHtml | trim | safe }}
{% endcall %}
{% else %}
{{ innerHtml | trim | safe }}
{% endif %}
</div>