Components Date input The date input component consists of three grouped text fields that invite users to enter a day, a month, and a year. This is the easiest way for users to enter dates they know well.
Examples Interact with each example to see how it works.
Code Mustache / Handlebars // Developer note: ensure your ".mustache" files are imported as plain text. In Webpack you might use https://github.com/webpack-contrib/raw-loader
import Mustache from "mustache";
import DateInput from "@govtnz/ds/build/mustache/DateInput.mustache";
import H1 from "@govtnz/ds/build/mustache/H1.mustache";
// The variables DateInput, H1 are all strings that are mustache templates.
export default `${Mustache.render(DateInput, {
id: `passport-issued`,
hintId: `passport-issued-hint`,
dayId: `passport-issued-day`,
monthId: `passport-issued-month`,
yearId: `passport-issued-year`,
label: `${Mustache.render(H1, {
"styleSize=large": true,
styleSize: true,
marginBottom0: ``,
children: `When was your passport issued?`
})}`,
hint: `For example, 12 11 2007`
})}`;
React (JavaScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-js/DateInput";
import "@govtnz/ds/build/css/DateInput.css"; // or @govtnz/ds/build/scss/DateInput.scss
import H1 from "@govtnz/ds/build/react-js/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
/>
);
React (TypeScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-ts/DateInput";
import "@govtnz/ds/build/css/DateInput.css"; // or @govtnz/ds/build/scss/DateInput.scss
import H1 from "@govtnz/ds/build/react-ts/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
/>
);
React with Styled Components (JavaScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-js-styled-components/DateInput";
import H1 from "@govtnz/ds/build/react-js-styled-components/H1";
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
/>
);
React with Styled Components (TypeScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-ts-styled-components/DateInput";
import H1 from "@govtnz/ds/build/react-ts-styled-components/H1";
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
/>
);
Vue (JavaScript) <template>
<date-input
id="passport-issued"
hintId="passport-issued-hint"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label="When was your passport issued?"
hint="For example, 12 11 2007"
/>
</template>
<script>
import Vue from "vue";
import DateInput from "@govtnz/ds/build/vue-js/DateInput.vue";
import H1 from "@govtnz/ds/build/vue-js/H1.vue";
export default { components: { "date-input": DateInput, "c-h1": H1 } };
</script>
Vue (TypeScript) <template>
<date-input
id="passport-issued"
hintId="passport-issued-hint"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label="When was your passport issued?"
hint="For example, 12 11 2007"
/>
</template>
<script lang="ts">
import Vue from "vue";
import DateInput from "@govtnz/ds/build/vue-ts/DateInput.vue";
import H1 from "@govtnz/ds/build/vue-ts/H1.vue";
export default { components: { "date-input": DateInput, "c-h1": H1 } };
</script>
HTML <!--
Remember to add these styles:
in CSS: DateInput.css, H1.css
OR in Sass (SCSS): DateInput.scss, H1.scss
-->
<div class="g-dateInput-form-group">
<fieldset
class="g-dateInput-fieldset"
aria-describedby="passport-issued-hint"
role="group"
>
<legend class="g-dateInput-fieldset__legend">
<h1 class="g-heading g-heading-l g-heading-mb-0">
When was your passport issued?
</h1>
</legend>
<span id="passport-issued-hint" class="g-dateInput-hint">
For example, 12 11 2007
</span>
<div id="passport-issued" class="g-dateInput">
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label
class="g-dateInput-label g-dateInput__label"
for="passport-issued-day"
>
Day
</label>
<input
id="passport-issued-day"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-2"
type="text"
maxlength="2"
pattern="[0-9]*"
/>
</div>
</div>
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label
class="g-dateInput-label g-dateInput__label"
for="passport-issued-month"
>
Month
</label>
<input
id="passport-issued-month"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-2"
type="text"
maxlength="2"
pattern="[0-9]*"
/>
</div>
</div>
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label
class="g-dateInput-label g-dateInput__label"
for="passport-issued-year"
>
Year
</label>
<input
id="passport-issued-year"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-4"
type="text"
maxlength="4"
pattern="[0-9]*"
/>
</div>
</div>
</div>
</fieldset>
</div>
twig-embed {% embed "DateInput.html.twig" with {'id':'passport-issued', 'hintId':'passport-issued-hint', 'dayId':'passport-issued-day', 'monthId':'passport-issued-month', 'yearId':'passport-issued-year', 'hint':'For example, 12 11 2007'} only %}{% block label %}{% embed "H1.html.twig" with {'styleSize':'large', 'marginBottom0':'true', 'children':'When was your passport issued?'} only %}{% endembed %}{% endblock %}{% endembed %}
Error
Code Mustache / Handlebars // Developer note: ensure your ".mustache" files are imported as plain text. In Webpack you might use https://github.com/webpack-contrib/raw-loader
import Mustache from "mustache";
import DateInput from "@govtnz/ds/build/mustache/DateInput.mustache";
import H1 from "@govtnz/ds/build/mustache/H1.mustache";
// The variables DateInput, H1 are all strings that are mustache templates.
export default `${Mustache.render(DateInput, {
id: `passport-issued`,
hintId: `passport-issued-hint`,
errorId: true,
dayId: `passport-issued-day`,
monthId: `passport-issued-month`,
yearId: `passport-issued-year`,
label: `${Mustache.render(H1, {
"styleSize=large": true,
styleSize: true,
marginBottom0: ``,
children: `When was your passport issued?`
})}`,
hint: `For example, 12 11 2007`,
value: `6`,
value2: `3`,
value3: `2076`,
error: `The date your passport was issued must be in the past`
})}`;
React (JavaScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-js/DateInput";
import "@govtnz/ds/build/css/DateInput.css"; // or @govtnz/ds/build/scss/DateInput.scss
import H1 from "@govtnz/ds/build/react-js/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
);
React (TypeScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-ts/DateInput";
import "@govtnz/ds/build/css/DateInput.css"; // or @govtnz/ds/build/scss/DateInput.scss
import H1 from "@govtnz/ds/build/react-ts/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
);
React with Styled Components (JavaScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-js-styled-components/DateInput";
import H1 from "@govtnz/ds/build/react-js-styled-components/H1";
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
);
React with Styled Components (TypeScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-ts-styled-components/DateInput";
import H1 from "@govtnz/ds/build/react-ts-styled-components/H1";
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
);
Vue (JavaScript) <template>
<date-input
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label="When was your passport issued?"
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
</template>
<script>
import Vue from "vue";
import DateInput from "@govtnz/ds/build/vue-js/DateInput.vue";
import H1 from "@govtnz/ds/build/vue-js/H1.vue";
export default { components: { "date-input": DateInput, "c-h1": H1 } };
</script>
Vue (TypeScript) <template>
<date-input
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label="When was your passport issued?"
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
</template>
<script lang="ts">
import Vue from "vue";
import DateInput from "@govtnz/ds/build/vue-ts/DateInput.vue";
import H1 from "@govtnz/ds/build/vue-ts/H1.vue";
export default { components: { "date-input": DateInput, "c-h1": H1 } };
</script>
HTML <!--
Remember to add these styles:
in CSS: DateInput.css, H1.css
OR in Sass (SCSS): DateInput.scss, H1.scss
-->
<div class="g-dateInput-form-group">
<fieldset
class="g-dateInput-fieldset"
aria-describedby="passport-issued-hint passport-issued-error"
role="group"
>
<legend class="g-dateInput-fieldset__legend">
<h1 class="g-heading g-heading-l g-heading-mb-0">
When was your passport issued?
</h1>
</legend>
<span id="passport-issued-hint" class="g-dateInput-hint">
For example, 12 11 2007
</span>
<span id="passport-issued-error" class="g-dateInput-error-message">
<span class="g-dateInput-visually-hidden"> Error: </span> The date your
passport was issued must be in the past
</span>
<div id="passport-issued" class="g-dateInput">
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label
class="g-dateInput-label g-dateInput__label"
for="passport-issued-day"
>
Day
</label>
<input
id="passport-issued-day"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-2"
type="text"
value="6"
maxlength="2"
pattern="[0-9]*"
/>
</div>
</div>
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label
class="g-dateInput-label g-dateInput__label"
for="passport-issued-month"
>
Month
</label>
<input
id="passport-issued-month"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-2"
type="text"
value="3"
maxlength="2"
pattern="[0-9]*"
/>
</div>
</div>
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label
class="g-dateInput-label g-dateInput__label"
for="passport-issued-year"
>
Year
</label>
<input
id="passport-issued-year"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-4"
value="2076"
type="text"
maxlength="4"
pattern="[0-9]*"
/>
</div>
</div>
</div>
</fieldset>
</div>
twig-embed {% embed "DateInput.html.twig" with {'id':'passport-issued', 'hintId':'passport-issued-hint', 'errorId':'passport-issued-error', 'dayId':'passport-issued-day', 'monthId':'passport-issued-month', 'yearId':'passport-issued-year', 'hint':'For example, 12 11 2007', 'value':'6', 'value2':'3', 'value3':'2076', 'error':'The date your passport was issued must be in the past'} only %}{% block label %}{% embed "H1.html.twig" with {'styleSize':'large', 'marginBottom0':'true', 'children':'When was your passport issued?'} only %}{% endembed %}{% endblock %}{% endembed %}
When to use it Use the date input component when you're asking users for a date they'll already know, or one they can look up easily.
When not to use it Do not use the date input component if users are unlikely to know the exact date of the event you're asking about.
How it works The three fields in the date input component are grouped together in a fieldset
with a legend
that describes them, as shown in the examples on this page. The legend is usually a question, such as 'What is your date of birth?'.
If you're asking one question per page, you can set the contents of the legend
as the page heading. This is good practice as it means that users of screen readers will only hear the contents once.
Never automatically move focus between the fields of the date input because this can confuse users and may clash with normal keyboard controls.
Use the autocomplete attribute for a date of birth Use the autocomplete
attribute on the date input component when you're asking for a date of birth. This allows browsers to autofill the information on a user's behalf if they've entered it previously.
To enable this functionality, set the autocomplete
attribute on the fields to bday-day
, bday-month
, and bday-year
. You'll need to do this to meet WCAG 2.1 Level AA.
Code Mustache / Handlebars // Developer note: ensure your ".mustache" files are imported as plain text. In Webpack you might use https://github.com/webpack-contrib/raw-loader
import Mustache from "mustache";
import DateInput from "@govtnz/ds/build/mustache/DateInput.mustache";
import H1 from "@govtnz/ds/build/mustache/H1.mustache";
// The variables DateInput, H1 are all strings that are mustache templates.
export default `${Mustache.render(DateInput, {
id: `bday`,
hintId: `bday-hint`,
dayId: `bday-day`,
monthId: `bday-month`,
yearId: `bday-year`,
label: `${Mustache.render(H1, {
"styleSize=large": true,
styleSize: true,
marginBottom0: ``,
children: `What is your date of birth?`
})}`,
hint: `For example, 31 3 1980`,
autoComplete: `birthday-day`,
autoComplete2: `birthday-month`,
autoComplete3: `birthday-year`
})}`;
React (JavaScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-js/DateInput";
import "@govtnz/ds/build/css/DateInput.css"; // or @govtnz/ds/build/scss/DateInput.scss
import H1 from "@govtnz/ds/build/react-js/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
export default () => (
<DateInput
id="bday"
hintId="bday-hint"
dayId="bday-day"
monthId="bday-month"
yearId="bday-year"
label={
<H1 styleSize="large" marginBottom0>
What is your date of birth?
</H1>
}
hint="For example, 31 3 1980"
autoComplete="birthday-day"
autoComplete2="birthday-month"
autoComplete3="birthday-year"
/>
);
React (TypeScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-ts/DateInput";
import "@govtnz/ds/build/css/DateInput.css"; // or @govtnz/ds/build/scss/DateInput.scss
import H1 from "@govtnz/ds/build/react-ts/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
export default () => (
<DateInput
id="bday"
hintId="bday-hint"
dayId="bday-day"
monthId="bday-month"
yearId="bday-year"
label={
<H1 styleSize="large" marginBottom0>
What is your date of birth?
</H1>
}
hint="For example, 31 3 1980"
autoComplete="birthday-day"
autoComplete2="birthday-month"
autoComplete3="birthday-year"
/>
);
React with Styled Components (JavaScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-js-styled-components/DateInput";
import H1 from "@govtnz/ds/build/react-js-styled-components/H1";
export default () => (
<DateInput
id="bday"
hintId="bday-hint"
dayId="bday-day"
monthId="bday-month"
yearId="bday-year"
label={
<H1 styleSize="large" marginBottom0>
What is your date of birth?
</H1>
}
hint="For example, 31 3 1980"
autoComplete="birthday-day"
autoComplete2="birthday-month"
autoComplete3="birthday-year"
/>
);
React with Styled Components (TypeScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-ts-styled-components/DateInput";
import H1 from "@govtnz/ds/build/react-ts-styled-components/H1";
export default () => (
<DateInput
id="bday"
hintId="bday-hint"
dayId="bday-day"
monthId="bday-month"
yearId="bday-year"
label={
<H1 styleSize="large" marginBottom0>
What is your date of birth?
</H1>
}
hint="For example, 31 3 1980"
autoComplete="birthday-day"
autoComplete2="birthday-month"
autoComplete3="birthday-year"
/>
);
Vue (JavaScript) <template>
<date-input
id="bday"
hintId="bday-hint"
dayId="bday-day"
monthId="bday-month"
yearId="bday-year"
label="What is your date of birth?"
hint="For example, 31 3 1980"
autoComplete="birthday-day"
autoComplete2="birthday-month"
autoComplete3="birthday-year"
/>
</template>
<script>
import Vue from "vue";
import DateInput from "@govtnz/ds/build/vue-js/DateInput.vue";
import H1 from "@govtnz/ds/build/vue-js/H1.vue";
export default { components: { "date-input": DateInput, "c-h1": H1 } };
</script>
Vue (TypeScript) <template>
<date-input
id="bday"
hintId="bday-hint"
dayId="bday-day"
monthId="bday-month"
yearId="bday-year"
label="What is your date of birth?"
hint="For example, 31 3 1980"
autoComplete="birthday-day"
autoComplete2="birthday-month"
autoComplete3="birthday-year"
/>
</template>
<script lang="ts">
import Vue from "vue";
import DateInput from "@govtnz/ds/build/vue-ts/DateInput.vue";
import H1 from "@govtnz/ds/build/vue-ts/H1.vue";
export default { components: { "date-input": DateInput, "c-h1": H1 } };
</script>
HTML <!--
Remember to add these styles:
in CSS: DateInput.css, H1.css
OR in Sass (SCSS): DateInput.scss, H1.scss
-->
<div class="g-dateInput-form-group">
<fieldset
class="g-dateInput-fieldset"
aria-describedby="bday-hint"
role="group"
>
<legend class="g-dateInput-fieldset__legend">
<h1 class="g-heading g-heading-l g-heading-mb-0">
What is your date of birth?
</h1>
</legend>
<span id="bday-hint" class="g-dateInput-hint">
For example, 31 3 1980
</span>
<div id="bday" class="g-dateInput">
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label class="g-dateInput-label g-dateInput__label" for="bday-day">
Day
</label>
<input
id="bday-day"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-2"
type="text"
maxlength="2"
pattern="[0-9]*"
autocomplete="birthday-day"
/>
</div>
</div>
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label class="g-dateInput-label g-dateInput__label" for="bday-month">
Month
</label>
<input
id="bday-month"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-2"
type="text"
maxlength="2"
pattern="[0-9]*"
autocomplete="birthday-day"
/>
</div>
</div>
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label class="g-dateInput-label g-dateInput__label" for="bday-year">
Year
</label>
<input
id="bday-year"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-4"
type="text"
maxlength="4"
pattern="[0-9]*"
autocomplete="birthday-day"
/>
</div>
</div>
</div>
</fieldset>
</div>
twig-embed {% embed "DateInput.html.twig" with {'id':'bday', 'hintId':'bday-hint', 'dayId':'bday-day', 'monthId':'bday-month', 'yearId':'bday-year', 'hint':'For example, 31 3 1980', 'autoComplete':'birthday-day', 'autoComplete2':'birthday-month', 'autoComplete3':'birthday-year'} only %}{% block label %}{% embed "H1.html.twig" with {'styleSize':'large', 'marginBottom0':'true', 'children':'What is your date of birth?'} only %}{% endembed %}{% endblock %}{% endembed %}
Error messages Style error messages as shown in the following example.
Error
Code Mustache / Handlebars // Developer note: ensure your ".mustache" files are imported as plain text. In Webpack you might use https://github.com/webpack-contrib/raw-loader
import Mustache from "mustache";
import DateInput from "@govtnz/ds/build/mustache/DateInput.mustache";
import H1 from "@govtnz/ds/build/mustache/H1.mustache";
// The variables DateInput, H1 are all strings that are mustache templates.
export default `${Mustache.render(DateInput, {
id: `passport-issued`,
hintId: `passport-issued-hint`,
errorId: true,
dayId: `passport-issued-day`,
monthId: `passport-issued-month`,
yearId: `passport-issued-year`,
label: `${Mustache.render(H1, {
"styleSize=large": true,
styleSize: true,
marginBottom0: ``,
children: `When was your passport issued?`
})}`,
hint: `For example, 12 11 2007`,
value: `6`,
value2: `3`,
value3: `2076`,
error: `The date your passport was issued must be in the past`
})}`;
React (JavaScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-js/DateInput";
import "@govtnz/ds/build/css/DateInput.css"; // or @govtnz/ds/build/scss/DateInput.scss
import H1 from "@govtnz/ds/build/react-js/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
);
React (TypeScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-ts/DateInput";
import "@govtnz/ds/build/css/DateInput.css"; // or @govtnz/ds/build/scss/DateInput.scss
import H1 from "@govtnz/ds/build/react-ts/H1";
import "@govtnz/ds/build/css/H1.css"; // or @govtnz/ds/build/scss/H1.scss
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
);
React with Styled Components (JavaScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-js-styled-components/DateInput";
import H1 from "@govtnz/ds/build/react-js-styled-components/H1";
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
);
React with Styled Components (TypeScript) import React from "react";
import DateInput from "@govtnz/ds/build/react-ts-styled-components/DateInput";
import H1 from "@govtnz/ds/build/react-ts-styled-components/H1";
export default () => (
<DateInput
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label={
<H1 styleSize="large" marginBottom0>
When was your passport issued?
</H1>
}
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
);
Vue (JavaScript) <template>
<date-input
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label="When was your passport issued?"
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
</template>
<script>
import Vue from "vue";
import DateInput from "@govtnz/ds/build/vue-js/DateInput.vue";
import H1 from "@govtnz/ds/build/vue-js/H1.vue";
export default { components: { "date-input": DateInput, "c-h1": H1 } };
</script>
Vue (TypeScript) <template>
<date-input
id="passport-issued"
hintId="passport-issued-hint"
errorId="passport-issued-error"
dayId="passport-issued-day"
monthId="passport-issued-month"
yearId="passport-issued-year"
label="When was your passport issued?"
hint="For example, 12 11 2007"
value="6"
value2="3"
value3="2076"
error="The date your passport was issued must be in the past"
/>
</template>
<script lang="ts">
import Vue from "vue";
import DateInput from "@govtnz/ds/build/vue-ts/DateInput.vue";
import H1 from "@govtnz/ds/build/vue-ts/H1.vue";
export default { components: { "date-input": DateInput, "c-h1": H1 } };
</script>
HTML <!--
Remember to add these styles:
in CSS: DateInput.css, H1.css
OR in Sass (SCSS): DateInput.scss, H1.scss
-->
<div class="g-dateInput-form-group">
<fieldset
class="g-dateInput-fieldset"
aria-describedby="passport-issued-hint passport-issued-error"
role="group"
>
<legend class="g-dateInput-fieldset__legend">
<h1 class="g-heading g-heading-l g-heading-mb-0">
When was your passport issued?
</h1>
</legend>
<span id="passport-issued-hint" class="g-dateInput-hint">
For example, 12 11 2007
</span>
<span id="passport-issued-error" class="g-dateInput-error-message">
<span class="g-dateInput-visually-hidden"> Error: </span> The date your
passport was issued must be in the past
</span>
<div id="passport-issued" class="g-dateInput">
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label
class="g-dateInput-label g-dateInput__label"
for="passport-issued-day"
>
Day
</label>
<input
id="passport-issued-day"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-2"
type="text"
value="6"
maxlength="2"
pattern="[0-9]*"
/>
</div>
</div>
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label
class="g-dateInput-label g-dateInput__label"
for="passport-issued-month"
>
Month
</label>
<input
id="passport-issued-month"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-2"
type="text"
value="3"
maxlength="2"
pattern="[0-9]*"
/>
</div>
</div>
<div class="g-dateInput__item">
<div class="g-dateInput-form-group">
<label
class="g-dateInput-label g-dateInput__label"
for="passport-issued-year"
>
Year
</label>
<input
id="passport-issued-year"
class="g-dateInput-input g-dateInput__input g-dateInput-input--width-4"
value="2076"
type="text"
maxlength="4"
pattern="[0-9]*"
/>
</div>
</div>
</div>
</fieldset>
</div>
twig-embed {% embed "DateInput.html.twig" with {'id':'passport-issued', 'hintId':'passport-issued-hint', 'errorId':'passport-issued-error', 'dayId':'passport-issued-day', 'monthId':'passport-issued-month', 'yearId':'passport-issued-year', 'hint':'For example, 12 11 2007', 'value':'6', 'value2':'3', 'value3':'2076', 'error':'The date your passport was issued must be in the past'} only %}{% block label %}{% embed "H1.html.twig" with {'styleSize':'large', 'marginBottom0':'true', 'children':'When was your passport issued?'} only %}{% endembed %}{% endblock %}{% endembed %}
Write a specific error message for every possible error state.
When setting up errors, check the entire date as a whole, rather than separately checking the day, month, and year.
Avoid assuming what is wrong with the date entered. For example, if a user enters '31 2 2016', the day may be right and the month may be wrong. An error message that mentions February may be confusing if they meant to enter '1' in the month field.
If nothing is entered Say 'Enter [type of date]'.
For example, 'Enter your date of birth'.
If an incomplete date is entered and you know what's missing Say '[type of date] must include a [what is missing]'.
For example, 'Date of birth must include a month' or 'Date of birth must include a day and a month'.
If an incomplete date is entered and you don't know what is missing Say 'Enter [type of date], and include a day, a month, and a year'.
For example, 'Enter your date of birth, and include a day, a month, and a year'.
If the date entered is not a real one Say 'Enter a real [type of date]'.
For example, 'Enter a real date of birth'.
If the date is in the future when it needs to be in the past Say '[type of date] must be in the past'.
For example, 'Date of birth must be in the past'.
If the date is in the future when it needs to be today or in the past Say '[type of date] must be today or in the past'.
For example, 'Date of birth must be today or in the past'.
If the date is in the past when it needs to be in the future Say '[type of date] must be in the future'.
For example, 'The date your course ends must be in the future'.
If the date is in the past when it needs to be today or in the future Say '[type of date] must be today or in the future'.
For example, 'The date your course ends must be today or in the future'.
If the date must be the same as or after another date Say '[type of date] must be the same as or after [date and optional description]'.
For example, 'The date your course ends must be the same as or after 1 September 2017 when you started the course'.
If the date must be after another date Say '[type of date] must be after [date and optional description]'.
For example, 'The date your course ends must be after 1 September 2017'.
If the date must be the same as or before another date Say '[type of date] must be the same as or before [date and optional description]'.
For example, 'The date of Gordon's last exam must be the same as or before 31 August 2017 when they left school'.
If the date must be before another date Say '[type of date] must be before [date and optional description]'.
For example, 'The date of Gordon's last exam must be the same as or before 31 August 2017'.
If the date must be between two dates Say '[type of date] must be between [date] and [date and optional description]'.
For example, 'The date your contract started must be between 1 September 2017 and 30 September 2017 when you became self-employed'.
Research on this component If you've used this component, get in touch to share your user research findings.
More research is needed to determine the extent to which users struggle to enter months as numbers, and whether allowing them to enter months as text is helpful.
Credit Guidance, original HTML and CSS derived from GOV.UK Design System .
Get in touch If you’ve got a question, idea, or suggestion, email the Design System (DS) team at info@digital.govt.nz , use our NZGDS Slack app , or discuss Date input on 'GitHub issues'.