|
| 1 | +{% from "nhsuk/macros/attributes.njk" import nhsukAttributes %} |
1 | 2 | {% from "nhsuk/components/error-message/macro.njk" import errorMessage -%} |
2 | 3 | {% from "nhsuk/components/hint/macro.njk" import hint %} |
3 | 4 | {% from "nhsuk/components/label/macro.njk" import label %} |
4 | | -{% from "nhsuk/macros/attributes.njk" import nhsukAttributes %} |
5 | 5 |
|
6 | 6 | {#- a record of other elements that we need to associate with the input using |
7 | | - aria-describedby – for example hints or error messages -#} |
8 | | -{%- set describedBy = params.describedBy if params.describedBy else "" -%} |
| 7 | + aria-describedby – for example hints or error messages -#} |
| 8 | +{% set describedBy = params.describedBy if params.describedBy else "" %} |
9 | 9 | {%- set id = params.id if params.id else params.name -%} |
10 | 10 |
|
11 | 11 | <div class="nhsuk-form-group {%- if params.errorMessage %} nhsuk-form-group--error{% endif %} {%- if params.formGroup.classes %} {{ params.formGroup.classes }}{% endif %}" |
|
17 | 17 | isPageHeading: params.label.isPageHeading, |
18 | 18 | attributes: params.label.attributes, |
19 | 19 | for: id |
20 | | - }) | indent(2) | trim }} |
21 | | -{%- if params.hint %} |
22 | | - {%- set hintId = id + '-hint' %} |
23 | | - {%- set describedBy = describedBy + ' ' + hintId if describedBy else hintId %} |
| 20 | + }) | trim | indent(2) }} |
| 21 | +{% if params.hint %} |
| 22 | + {% set hintId = id + '-hint' %} |
| 23 | + {% set describedBy = describedBy + ' ' + hintId if describedBy else hintId %} |
24 | 24 | {{ hint({ |
25 | 25 | id: hintId, |
26 | 26 | classes: params.hint.classes, |
27 | 27 | attributes: params.hint.attributes, |
28 | 28 | html: params.hint.html, |
29 | 29 | text: params.hint.text |
30 | | - }) | indent(2) | trim }} |
31 | | -{%- endif -%} |
32 | | -{%- if params.errorMessage %} |
33 | | - {%- set errorId = id + '-error' %} |
34 | | - {%- set describedBy = describedBy + ' ' + errorId if describedBy else errorId %} |
| 30 | + }) | trim | indent(2) }} |
| 31 | +{% endif %} |
| 32 | +{% if params.errorMessage %} |
| 33 | + {% set errorId = id + '-error' %} |
| 34 | + {% set describedBy = describedBy + ' ' + errorId if describedBy else errorId %} |
35 | 35 | {{ errorMessage({ |
36 | 36 | id: errorId, |
37 | 37 | classes: params.errorMessage.classes, |
| 38 | + attributes: params.errorMessage.attributes, |
38 | 39 | html: params.errorMessage.html, |
39 | | - text: params.errorMessage.text |
40 | | - }) | indent(2) | trim }} |
41 | | -{%- endif %} |
| 40 | + text: params.errorMessage.text, |
| 41 | + visuallyHiddenText: params.errorMessage.visuallyHiddenText |
| 42 | + }) | trim | indent(2) }} |
| 43 | +{% endif %} |
42 | 44 | {% if params.formGroup.beforeInput %} |
43 | 45 | {{ params.formGroup.beforeInput.html | safe | trim | indent(2) if params.formGroup.beforeInput.html else params.formGroup.beforeInput.text }} |
44 | 46 | {% endif %} |
|
47 | 49 | {%- if params.disabled %} disabled{% endif %} |
48 | 50 | {%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %} |
49 | 51 | {{- nhsukAttributes(params.attributes) }}> |
50 | | - {%- for item in params.items %} |
| 52 | + {% for item in params.items %} |
51 | 53 | {% if item %} |
52 | 54 | {#- Allow selecting by text content (the value for an option when no value attribute is specified) #} |
53 | 55 | {%- set effectiveValue = item.value | default(item.text) %} |
|
58 | 60 | {{- item.text -}} |
59 | 61 | </option> |
60 | 62 | {% endif %} |
61 | | - {%- endfor %} |
| 63 | + {% endfor %} |
62 | 64 | </select> |
63 | 65 | {% if params.formGroup.afterInput %} |
64 | 66 | {{ params.formGroup.afterInput.html | safe | trim | indent(2) if params.formGroup.afterInput.html else params.formGroup.afterInput.text }} |
|
0 commit comments