Skip to content

Commit

Permalink
Add default date-input items
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ju committed Jul 2, 2018
1 parent 5d87a79 commit 8bcd22f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/components/date-input/date-input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,12 @@ examples:
-
name: year
classes: govuk-input--width-4 govuk-input--error
- name: with default items
data:
id: dob
name: dob
fieldset:
legend:
text: What is your date of birth?
hint:
text: For example, 31 3 1980
21 changes: 20 additions & 1 deletion src/components/date-input/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@
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 %}
Expand All @@ -33,7 +52,7 @@
<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 params.items %}
{% for item in dateInputItems %}
<div class="govuk-date-input__item">
{{ govukInput({
label: {
Expand Down

0 comments on commit 8bcd22f

Please sign in to comment.