REMOVED

This component has been removed from the Framework.

  • Atom
  • CORE COMPONENT
  • Taxonomic name: A-DATE
  • Added on: v3.0.0 (15/09/17)
  • Removed on: v5.0.0 (05/10/20)

Date - native date input variant

Date fields are a control for a recording a date by day, month and year.


Design and usage

  • Not all date formats are the same; use the appropriate date format based on the rules below.
  • Dates, open dates, or dates within a long range (5+ years): Provide three text input fields, with hint text of DD MM YYYY to aid users input; see the textbox group page for further details
  • Approximate dates: If an exact date is not required (eg. for 'Year built'), allow users to enter free format dates in a single auto-formatting textbox - see memorable date textbox page for further details
  • Time and days: Date and time should be separate fields; date data entry should follow patterns listed here. Do not allow users to select times (eg. when scheduling a callback) that are unavailable
  • Dates within a short range (0-12 months): provide a single input box with a date picker (mobile views utilise the native datepicker); date picker must only show a valid date range
  • Dates within a medium range (1-5 years): See date range control page for further details

Examples

Standard date

Interactive example

Code example

<div class="m-form-row">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<input class="a-date" type="date" max="..." min="..." name="..." placeholder="..." id="..." value="..." data-module="a-date" />
		...
	</div>
</div>

Standard date with optional datepicker heading

<div class="m-form-row">
		<label class="a-label" for="...">...</label>
		<div class="m-form-row__content">
			<input class="a-date" type="date" max="..." min="..." name="..." placeholder="..." id="..." value="..." data-module="a-date" data-date-title="..." />
			...
		</div>
	</div>

Valid date

Interactive example

Code example

<div class="m-form-row is-valid">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<p class="m-form-row__validation-message">...</p>
		<input class="a-date" type="date" max="..." min="..." name="..." placeholder="..." id="..." value="..." data-module="a-date" />
		...
	</div>
</div>

Errored date

Interactive example

Code example

<div class="m-form-row is-error">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<p class="m-form-row__error-message">...</p>
		<input class="a-date" type="date" max="..." min="..." name="..." placeholder="..." id="..." value="..." data-module="a-date" aria-invalid="true" />
		...
	</div>
</div>

Disabled date

Interactive example

Code example

<div class="m-form-row is-disabled">
	<label class="a-label" for="...">...</label>
	<div class="m-form-row__content">
		<input class="a-date" type="date" max="..." min="..." name="..." placeholder="..." id="..." value="..." data-module="a-date" disabled />
		...
	</div>
</div>

Development and test

Notes for developers

The input must be of type date this enables the best experience for all users (in particular mobile user) as for modern browsers the user will get the native date control. For older browsers a JavaScript datepicker is enabled.

Note that browser that natively support the date input field will return the date in ISO format so both ISO and the appropriate format for the locale need to be supported within any validation.

When setting the value of the input field always set it in ISO format (YYYY-MM-DD).

For more information see the MDN web docs on the date input

The input must have the attributes min and max, in the format YYYY-MM-DD, set to limit the date pickers to a date range.

When disabling the date input do not solely rely on the is-disabled class, ensure that the disabled attribute is set on the input field.

If the native form validation needs to be disabled set the novalidate attribute on the form.

Important messages

To help those using assistive technologies, make sure that success/error messages which need to be announced to users have their aria attributes updated to role="alert" and/or aria-live="assertive".

Update value, minimum and/or maximum dates post load

When using the date input the value, minimum and maximum date settings can be updated post initial load. To update the component the function setSettings must be called from the a-date input with a JavaScript object containing settings in the same format as below being passed into the function.

Attribute Type Default Description
value String null Date must be in the format 'YYYY-MM-DD'
minDate String null Update the minimum date post load. Date must be in the format 'YYYY-MM-DD'
maxDate String null Update the maximum date post load. Date must be in the format 'YYYY-MM-DD'
document.querySelector( '#dateInput' ).dateInput.setSettings(
{
	minDate: '2016-01-01',
	maxDate: '2018-01-01',
}
);

Using autocomplete

Users appreciate when websites save them time by automatically filling common fields like names, email addresses and other frequently used fields, plus it helps to reduce potential input errors, especially on virtual keyboards and small devices.

Browsers use many methods to determine which fields they can auto-populate based on previously specified data by the user, and you can give hints to the browser by providing both the name attribute and the autocomplete attribute on each input element.

Further details can be found in the developer notes on the form introduction page.

Changing locale settings

The date format and the accessible text behind the next and previous arrows can be updated for a particular locale.

en: {
	datepicker: {
		locale: 'en-gb',
		previousMonth: 'Previous month',
		nextMonth: 'Next month',
		weekdaysShort: ['S','M','T','W','T','F','S'],
	},
},

For more information on this, see our page on how to change locale settings within JavaScript.

Available date format locales are:
af, ar-ma, ar-sa, ar-tn, ar, az, be, bg, bn, bo, br, bs, ca, cs, cv, cy, da, de-at, de, dv, el, en-au, en-ca, en-gb, en-ie, en-nz, eo, es-do, es, et, eu, fa, fi, fo, fr-ca, fr-ch, fr, fy, gd, dl, he, hi, hr, hu, hy-am, id, id, it, ja, jv, ka, kk, km, ko, ky, lb, lo, lt, lv, me, mk, ml, mr, ms-my, ms, my, nb, ne, nl, nn, pa-in, pl, pt-br, pt, ro, ru, se, si, sk, sl, sq, sr-cyrl, sr, ss, sv, sw, ta, te, th, tl-ph, tlh, tr, tzl, tzm-latn, tzm, uk, uz, vi, x-pseudo, zh-cn, zh-tw


Notes for testers

  • If the browser natively supports the date input the JavaScript datepicker will not be used.
  • In IE11 the date icon will look fuzzy; this is a rendering issue with the browser when a background is on an element that has rounded corners.
  • Depending on the browser's support of the date field, it may not limit the user to entering the date in a particular format; this is perfectly acceptable but the form must have validation in place to catch any errors with the dates entered and present an error message back to the user. This message does not have to be shown real-time, but can appear once the user has attempted to submit the form.
  • Ensure that the field has a correctly associated label; this not only provides context to the field for assistive technology users, but also a larger clickable area to select the field. Clicking / pressing on the label should cause the date field to gain focus.
  • Users should be able to copy and paste if necessary.
  • Highlight today's date and the selected date with clear variation between them
  • Users should be able to easily identify and distinguish between selectable and non-selectable dates, today's date, the selected date and weekends.
  • The calendar should have a clear hover state to help users identify the correct date.
  • For some applications, past dates may need to be disabled.
  • Clickable / tappable area of each day should be an appropriate size.

Classes overview

The following table gives you a quick overview of the CSS classes that can be applied.

Class Outcome Required Applied to Comments
.a-date Styling for the date input Yes input  

Component releases

  • Added on: v3.0.0 (15/09/17)
  • Removed on: v5.0.0 (05/10/20)

Latest update:

Full version history

A full history of changes and enhancements detailing all minor and major updates to the component.

View full version history

Want something new in Framework, or to chat about an issue you're having with it?

Contact the team