Skip to content

Commit

Permalink
Make it easier to set date values
Browse files Browse the repository at this point in the history
  • Loading branch information
frankieroberto committed Aug 16, 2024
1 parent 1ff76e3 commit 6e8a979
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
16 changes: 1 addition & 15 deletions app/components/date-input/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,7 @@
},
"hint": {
"text": "For example, 31 3 1980"
},
"items": [
{
"name": "day",
"classes": "nhsuk-input--width-2"
},
{
"name": "month",
"classes": "nhsuk-input--width-2"
},
{
"name": "year",
"classes": "nhsuk-input--width-4"
}
]
}
}) }}
</div>
</div>
Expand Down
36 changes: 36 additions & 0 deletions app/components/date-input/with-values.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% set html_style = 'background-color: #f0f4f5;' %}
{% set title = 'Date input' %}
{% from 'components/date-input/macro.njk' import dateInput %}
{% extends 'layout.njk' %}

{% block body %}

<div class="nhsuk-width-container">
<main class="nhsuk-main-wrapper" id="maincontent">

<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
{{ dateInput({
"id": "dob",
"namePrefix": "dob",
"fieldset": {
"legend": {
"text": "What is your date of birth?"
}
},
"hint": {
"text": "For example, 31 3 1980"
},
values: {
day: "5",
month: "8",
year: "2024"
}
}) }}
</div>
</div>

</main>
</div>

{% endblock %}
1 change: 1 addition & 0 deletions app/pages/examples.njk
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<li><a href="../components/date-input/autocomplete.html">Date input with autocomplete attribute</a></li>
<li><a href="../components/date-input/error.html">Date input with error</a></li>
<li><a href="../components/date-input/multiple-errors.html">Date input with multiple errors</a></li>
<li><a href="../components/date-input/with-values.html">Date input with values</a></li>
<li><a href="../components/details/index.html">Details</a></li>
<li><a href="../components/do-dont-list/index.html">Do and Don't list</a></li>
<li><a href="../components/error-message/index.html">Error message</a></li>
Expand Down
11 changes: 7 additions & 4 deletions packages/components/date-input/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
{% set dateInputItems = [
{
name: "day",
classes: "nhsuk-input--width-2"
classes: "nhsuk-input--width-2",
value: params.values.day
},
{
name: "month",
classes: "nhsuk-input--width-2"
classes: "nhsuk-input--width-2",
value: params.values.month
},
{
name: "year",
classes: "nhsuk-input--width-4"
classes: "nhsuk-input--width-4",
value: params.values.year
}
] %}
{% endif %}
Expand Down Expand Up @@ -63,7 +66,7 @@
},
id: item.id if item.id else (params.id + "-" + item.name),
classes: "nhsuk-date-input__input " + (item.classes if item.classes),
name: (params.namePrefix + "-" + item.name) if params.namePrefix else item.name,
name: (params.namePrefix + "[" + item.name + "]") if params.namePrefix else item.name,
value: item.value,
inputmode: item.inputmode if item.inputmode else "numeric",
autocomplete: item.autocomplete,
Expand Down

0 comments on commit 6e8a979

Please sign in to comment.