Date input examples
-
# default
{ "id": "dob", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" } }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" } }) }} -
# day and month
{ "id": "bday", "namePrefix": "bday", "fieldset": { "legend": { "text": "What is your birthday?" } }, "hint": { "text": "For example, 5 12" }, "items": [ { "name": "day", "classes": "govuk-input--width-2" }, { "name": "month", "classes": "govuk-input--width-2" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "bday", "namePrefix": "bday", "fieldset": { "legend": { "text": "What is your birthday?" } }, "hint": { "text": "For example, 5 12" }, "items": [ { "name": "day", "classes": "govuk-input--width-2" }, { "name": "month", "classes": "govuk-input--width-2" } ] }) }} -
# month and year
{ "id": "dob", "namePrefix": "dob", "fieldset": { "legend": { "text": "When did you move to this property?" } }, "hint": { "text": "For example, 3 1980" }, "items": [ { "name": "month", "classes": "govuk-input--width-2" }, { "name": "year", "classes": "govuk-input--width-4" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob", "namePrefix": "dob", "fieldset": { "legend": { "text": "When did you move to this property?" } }, "hint": { "text": "For example, 3 1980" }, "items": [ { "name": "month", "classes": "govuk-input--width-2" }, { "name": "year", "classes": "govuk-input--width-4" } ] }) }} -
# with errors only
{ "id": "dob-errors", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "month", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "year", "classes": "govuk-input--width-4 govuk-input--error" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob-errors", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "month", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "year", "classes": "govuk-input--width-4 govuk-input--error" } ] }) }} -
# with errors and hint
{ "id": "dob-errors", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "month", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "year", "classes": "govuk-input--width-4 govuk-input--error" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob-errors", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "month", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "year", "classes": "govuk-input--width-4 govuk-input--error" } ] }) }} -
# with error on day input
{ "id": "dob-day-error", "namePrefix": "dob-day-error", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "month", "classes": "govuk-input--width-2" }, { "name": "year", "classes": "govuk-input--width-4" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob-day-error", "namePrefix": "dob-day-error", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "month", "classes": "govuk-input--width-2" }, { "name": "year", "classes": "govuk-input--width-4" } ] }) }} -
# with error on month input
{ "id": "dob-month-error", "namePrefix": "dob-month-error", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2" }, { "name": "month", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "year", "classes": "govuk-input--width-4" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob-month-error", "namePrefix": "dob-month-error", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2" }, { "name": "month", "classes": "govuk-input--width-2 govuk-input--error" }, { "name": "year", "classes": "govuk-input--width-4" } ] }) }} -
# with error on year input
{ "id": "dob-year-error", "namePrefix": "dob-year-error", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2" }, { "name": "month", "classes": "govuk-input--width-2" }, { "name": "year", "classes": "govuk-input--width-4 govuk-input--error" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob-year-error", "namePrefix": "dob-year-error", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "errorMessage": { "text": "Error message goes here" }, "items": [ { "name": "day", "classes": "govuk-input--width-2" }, { "name": "month", "classes": "govuk-input--width-2" }, { "name": "year", "classes": "govuk-input--width-4 govuk-input--error" } ] }) }} -
# classes
-
# attributes
-
# with items
{ "id": "dob", "namePrefix": "dob", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "items": [ { "name": "day", "classes": "govuk-input--width-2" }, { "name": "month", "classes": "govuk-input--width-2" }, { "name": "year", "classes": "govuk-input--width-4" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob", "namePrefix": "dob", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "items": [ { "name": "day", "classes": "govuk-input--width-2" }, { "name": "month", "classes": "govuk-input--width-2" }, { "name": "year", "classes": "govuk-input--width-4" } ] }) }} -
# with empty items
-
# custom pattern
-
# custom inputmode
{ "id": "with-custom-inputmode", "items": [ { "name": "day", "pattern": "[0-9X]*", "inputmode": "text" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "with-custom-inputmode", "items": [ { "name": "day", "pattern": "[0-9X]*", "inputmode": "text" } ] }) }} -
# with nested name
{ "id": "with-nested-name", "items": [ { "name": "day[dd]" }, { "name": "month[mm]" }, { "name": "year[yyyy]" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "with-nested-name", "items": [ { "name": "day[dd]" }, { "name": "month[mm]" }, { "name": "year[yyyy]" } ] }) }} -
# with id on items
{ "id": "with-item-id", "items": [ { "id": "day", "name": "day" }, { "id": "month", "name": "month" }, { "id": "year", "name": "year" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "with-item-id", "items": [ { "id": "day", "name": "day" }, { "id": "month", "name": "month" }, { "id": "year", "name": "year" } ] }) }} -
# suffixed id
{ "id": "my-date-input", "items": [ { "name": "day" }, { "name": "month" }, { "name": "year" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "my-date-input", "items": [ { "name": "day" }, { "name": "month" }, { "name": "year" } ] }) }} -
# with values
{ "id": "with-values", "items": [ { "id": "day", "name": "day" }, { "id": "month", "name": "month" }, { "id": "year", "name": "year", "value": 2018 } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "with-values", "items": [ { "id": "day", "name": "day" }, { "id": "month", "name": "month" }, { "id": "year", "name": "year", "value": 2018 } ] }) }} -
# with hint and describedBy
{ "id": "dob-errors", "fieldset": { "describedBy": "test-target-element", "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" } }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob-errors", "fieldset": { "describedBy": "test-target-element", "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" } }) }} -
# with error and describedBy
{ "id": "dob-errors", "fieldset": { "describedBy": "test-target-element", "legend": { "text": "What is your date of birth?" } }, "errorMessage": { "text": "Error message goes here" } }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob-errors", "fieldset": { "describedBy": "test-target-element", "legend": { "text": "What is your date of birth?" } }, "errorMessage": { "text": "Error message goes here" } }) }} -
# fieldset html
{ "id": "with-fieldset-html", "fieldset": { "legend": { "html": "What is your <b>date of birth</b>?" } } }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "with-fieldset-html", "fieldset": { "legend": { "html": "What is your <b>date of birth</b>?" } } }) }} -
# items with classes
{ "id": "with-item-classes", "items": [ { "name": "day", "classes": "app-date-input__day" }, { "name": "month", "classes": "app-date-input__month" }, { "name": "year", "classes": "app-date-input__year" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "with-item-classes", "items": [ { "name": "day", "classes": "app-date-input__day" }, { "name": "month", "classes": "app-date-input__month" }, { "name": "year", "classes": "app-date-input__year" } ] }) }} -
# items without classes
{ "id": "without-item-classes", "items": [ { "name": "day" }, { "name": "month" }, { "name": "year" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "without-item-classes", "items": [ { "name": "day" }, { "name": "month" }, { "name": "year" } ] }) }} -
# with optional form-group classes
{ "id": "dob", "namePrefix": "dob", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "formGroup": { "classes": "extra-class" } }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob", "namePrefix": "dob", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "formGroup": { "classes": "extra-class" } }) }} -
# with autocomplete values
{ "id": "dob-with-autocomplete-attribute", "namePrefix": "dob-with-autocomplete", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "items": [ { "name": "day", "classes": "govuk-input--width-2", "autocomplete": "bday-day" }, { "name": "month", "classes": "govuk-input--width-2", "autocomplete": "bday-month" }, { "name": "year", "classes": "govuk-input--width-4", "autocomplete": "bday-year" } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob-with-autocomplete-attribute", "namePrefix": "dob-with-autocomplete", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "items": [ { "name": "day", "classes": "govuk-input--width-2", "autocomplete": "bday-day" }, { "name": "month", "classes": "govuk-input--width-2", "autocomplete": "bday-month" }, { "name": "year", "classes": "govuk-input--width-4", "autocomplete": "bday-year" } ] }) }} -
# with input attributes
{ "id": "dob-with-input-attributes", "namePrefix": "dob-with-input-attributes", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "items": [ { "name": "day", "classes": "govuk-input--width-2", "attributes": { "data-example-day": "day" } }, { "name": "month", "classes": "govuk-input--width-2", "attributes": { "data-example-month": "month" } }, { "name": "year", "classes": "govuk-input--width-4", "attributes": { "data-example-year": "year" } } ] }{% from "govuk/components/date-input/macro.njk" import govukDateInput %} {{ govukDateInput({ "id": "dob-with-input-attributes", "namePrefix": "dob-with-input-attributes", "fieldset": { "legend": { "text": "What is your date of birth?" } }, "hint": { "text": "For example, 31 3 1980" }, "items": [ { "name": "day", "classes": "govuk-input--width-2", "attributes": { "data-example-day": "day" } }, { "name": "month", "classes": "govuk-input--width-2", "attributes": { "data-example-month": "month" } }, { "name": "year", "classes": "govuk-input--width-4", "attributes": { "data-example-year": "year" } } ] }) }}