Component
Datetime fields (experimental)
Use the datetime fields component to help users enter a datetime for a specific event.
This differs from the Form date input component in a few notable ways. It builds upon that component by adding time fields. Times are chosen using select elements.
Overview
How it looks (preview) (preview all)
How to call this component
<%= render "govuk_publishing_components/components/datetime_fields", {} %>
GOV.UK Design System
This component incorporates components from the GOV.UK Design System:
Accessibility acceptance criteria
Inputs in the component must:
- accept focus
- be focusable with a keyboard
- be usable with a keyboard
- be usable with touch
- indicate when they have focus
- be recognisable as form input elements
- have correctly associated labels
Child components
This component contains the following components. Note that these components may also contain child components.
Other examples
Standard options
This component uses the component wrapper helper. It accepts the following options and applies them to the parent element of the component. See the component wrapper helper documentation for more detail.
See all standard options
id- accepts a string for the element ID attributedata_attributes- accepts a hash of data attributesaria- accepts a hash of aria attributesclasses- accepts a space separated string of classes, these should not be used for styling and must be prefixed withjs-margin_bottom- accepts a number from0to9(0pxto60px) using the GOV.UK Frontend spacing scalerole- accepts a space separated string of roleslang- accepts a language attribute valueopen- accepts an open attribute value (true or false)hidden- accepts an empty string, ‘hidden’, or ‘until-found’tabindex- accepts an integer. The integer can also be passed as a stringdir- accepts ‘rtl’, ‘ltr’, or ‘auto’type- accepts any valid type attribute e.g. ‘button’, ‘submit’, ‘text’rel- accepts any valid rel attribute e.g. ‘nofollow’target- accepts a valid target attribute e.g. ‘_blank’title- accepts any stringdraggable- accepts a draggable attribute value (“true” or “false”)
With custom field names and ids (preview)
<%= render "govuk_publishing_components/components/datetime_fields", {
year: {
name: "year_field_name",
id: "year_id"
},
month: {
name: "month_field_name",
id: "month_id"
},
day: {
name: "day_field_name",
id: "day_id"
},
hour: {
name: "hour_field_name",
id: "hour_id"
},
minute: {
name: "minute_field_name",
id: "minute_id"
}
} %>
With custom heading options (preview)
<%= render "govuk_publishing_components/components/datetime_fields", {
heading_level: 2,
heading_size: "l",
date_heading: "The date",
time_heading: "The time"
} %>
With hint text (preview)
<%= render "govuk_publishing_components/components/datetime_fields", {
date_hint: "For example, 01 August 2022",
time_hint: "For example, 09:30 or 19:30"
} %>
With values (preview)
<%= render "govuk_publishing_components/components/datetime_fields", {
year: {
value: 2022
},
month: {
value: 1
},
day: {
value: 2
},
hour: {
value: 9
},
minute: {
value: 30
}
} %>
With error items (preview)
<%= render "govuk_publishing_components/components/datetime_fields", {
error_items: [
{
text: "Descriptive error 1"
},
{
text: "Descriptive error 2"
}
]
} %>
With separate date time error items (preview)
<%= render "govuk_publishing_components/components/datetime_fields", {
error_items_date: [
{
text: "Descriptive date error 1"
},
{
text: "Descriptive date error 2"
}
],
error_items_time: [
{
text: "Descriptive time error 1"
},
{
text: "Descriptive time error 2"
}
]
} %>