Note:Any Coral CSS classes and attributes not explicitly mentioned in the public documentation are private and subject to change. Their direct use is not recommended and at high risk of breaking after subsequent updates of CoralUI library. For technical details of how to use Coral safely, please refer to the CoralUI Architecture.
The Datepicker component provides desktop and touch friendly for both date and time selection. The component leverages
moment.js for parsing, manipulating, and formatting dates.
<formclass="coral-Form coral-Form--vertical u-columnMedium"><sectionclass="coral-Form-fieldset"><divclass="coral-Form-fieldwrapper"><labelid="label-vertical-0"class="coral-Form-fieldlabel">Label</label><coral-datepickerclass="coral-Form-field"placeholder="Choose a date"name="name"labelledby="label-vertical-0"></coral-datepicker></div><divclass="coral-Form-fieldwrapper"><labelid="label-vertical-1"class="coral-Form-fieldlabel">Required</label><coral-datepickerclass="coral-Form-field"placeholder="Choose a date"name="name"labelledby="label-vertical-1"required></coral-datepicker><coral-iconclass="coral-Form-fieldinfo"icon="infoCircle"size="S"id="coral-form-vertical-datepicker-fieldinfo"></coral-icon><coral-tooltipvariant="info"placement="right"target="#coral-form-vertical-datepicker-fieldinfo">Required Information</coral-tooltip></div><divclass="coral-Form-fieldwrapper"><labelid="label-vertical-2"class="coral-Form-fieldlabel">Invalid</label><coral-datepickerclass="coral-Form-field"placeholder="Choose a date"name="name"labelledby="label-vertical-2"invalid></coral-datepicker><coral-iconclass="coral-Form-fielderror"icon="infoCircle"size="S"id="coral-form-vertical-datepicker-fielderror"></coral-icon><coral-tooltipvariant="error"placement="right"target="#coral-form-vertical-datepicker-fielderror">Error Message</coral-tooltip></div></section></form>
<formclass="coral-Form coral-Form--aligned u-columnLarge"><sectionclass="coral-Form-fieldset"><divclass="coral-Form-fieldwrapper"><labelid="label-aligned-0"class="coral-Form-fieldlabel">Label</label><coral-datepickerclass="coral-Form-field"placeholder="Choose a date"name="name"labelledby="label-aligned-0"></coral-datepicker></div><divclass="coral-Form-fieldwrapper"><labelid="label-aligned-1"class="coral-Form-fieldlabel">Required</label><coral-datepickerclass="coral-Form-field"placeholder="Choose a date"name="name"labelledby="label-aligned-1"required></coral-datepicker><coral-iconclass="coral-Form-fieldinfo"icon="infoCircle"size="S"id="coral-form-aligned-datepicker-fieldinfo"></coral-icon><coral-tooltipvariant="info"placement="right"target="#coral-form-aligned-datepicker-fieldinfo">Required Information</coral-tooltip></div><divclass="coral-Form-fieldwrapper"><labelid="label-aligned-2"class="coral-Form-fieldlabel">Invalid</label><coral-datepickerclass="coral-Form-field"placeholder="Choose a date"name="name"labelledby="label-aligned-2"invalid></coral-datepicker><coral-iconclass="coral-Form-fielderror"icon="infoCircle"size="S"id="coral-form-aligned-datepicker-fielderror"></coral-icon><coral-tooltipvariant="error"placement="right"target="#coral-form-aligned-datepicker-fielderror">Error Message</coral-tooltip></div></section></form>
The following example sets up the component to use the appropriate date formatting for the specified page locale (e.g. <html lang="fr-FR">). Requires moment-with-locales.js.
Note: moment-with-locales.js provides support to close to 100 locales. If maintaining minimal footprint is critical to your product, it's possible to generate a custom version (moment-with-locales.custom.js) that limits support to a set of languages you can specify.
The format used to display the selected date(time) to the user. If the user manually types a date, this format
will be used to parse the value. When using this component on a mobile device, the display format must follow
the format used by the native input. The default value depends on the type, which can be one from
YYYY-MM-DD, YYYY-MM-DD[T]HH:mmZ or HH:mm. If an empty string is provided,
then the default value per type will be used. See http://momentjs.com/docs/#/displaying/ for valid format string
options.
The format used to display the current month and year. See http://momentjs.com/docs/#/displaying/ for valid
format string options.
See Coral.Calendar#startDay
Reference to a space delimited set of ids for the HTML elements that provide a label for the formField.
Implementers should override this method to ensure that the appropriate descendant elements are labelled using the
aria-labelledby attribute. This will ensure that the component is properly identified for
accessibility purposes. It reflects the aria-labelledby attribute to the DOM.
The maximum date that the Datepicker will accept as valid. It must not be less than its minimum. It accepts both
date and string values. When a string is provided, it should match the Coral.Datepicker#valueFormat.
See Coral.Calendar#max
The minimum date that the Datepicker will accept as valid. It must not be greated that its maximum. It accepts
both date and string values. When a string is provided, it should match the
Coral.Datepicker#valueFormat.
See Coral.Calendar#min
Whether this field is readOnly or not. Indicating that the user cannot modify the value of the control.
This is ignored for checkbox, radio or fileupload.
The current value. When set to "today", the value is coerced into the client's local date expressed as string
formatted in accordance to the set valueFormat.
See Coral.Calendar#value
The format to use on expressing the selected date as a string on the value attribute. The value
will be sent to the server using this format. If an empty string is provided, then the default value per type
will be used. See http://momentjs.com/docs/#/displaying/ for valid format string options.
Non-destructively remove this element. It can be re-added by simply appending it to the document again.
It will be garbage collected if there are no more references to it.