Newer Version Available
ui:inputDate
An input field for entering a date.
A ui:inputDate component represents a date input field, which is rendered as an HTML input tag of type text. The value is displayed in the default format specified language locale of the browser.
This is a basic set up of a date field with a date picker, which displays the field value 1/30/2014. Specifying format="MMMM d, yyyy" renders the field value as January 30, 2014.
1<ui:inputDate aura:id="dateField" label="Birthday" value="2014-01-30" displayDatePicker="true"/>This example results in the following HTML.
1<div class="uiInput uiInputDate">
2 <label class="uiLabel-left uiLabel">
3 <span>Birthday</span>
4 </label>
5 <input placeholder="M/d/yyyy" type="text" class="uiInput uiInputDate">
6 <a class="datePicker-openIcon" aria-haspopup="true">
7 <span class="assistiveText">Date Picker</span>
8 </a>
9 <a class="clearIcon">
10 <span class="assistiveText">Clear Button</span>
11 </a>
12 <div class="uiDatePicker">
13 <!--Date picker set to visible when icon is clicked-->
14 </div>
15</div>
This example sets today's date on a ui:inputDate component, retrieves its value, and displays it using ui:outputDate. The init handler initializes and sets the date on the component.
1<aura:component>
2 <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
3 <aura:attribute name="today" type="Date" default=""/>
4
5 <ui:inputDate aura:id="expdate" label="Today's Date" class="field" value="{!v.today}" displayDatePicker="true" />
6 <ui:button class="btn" label="Submit" press="{!c.setOutput}"/>
7
8 <div aura:id="msg" class="hide">
9 You entered: <ui:outputDate aura:id="oDate" value="" />
10 </div>
11</aura:component>1swfobject.registerObject("clippy.codeblock-3", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17({
18 doInit : function(component, event, helper) {
19 var today = new Date();
20 component.set('v.today', today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate());
21 component.set('v.deadline', today);
22 },
23
24 setOutput : function(component, event, helper) {
25 var el = component.find("msg");
26 $A.util.removeClass(el.getElement(), 'hide');
27 var expdate = component.find("expdate").get("v.value");
28
29 var oDate = component.find("oDate");
30 oDate.set("v.value", expdate);
31
32 }
33})Attributes
| Attribute Name | Attribute Type | Description | Required? |
|---|---|---|---|
| body | Component[] | The body of the component. In markup, this is everything in the body of the tag. | |
| class | String | A CSS style to be attached to the component. This style is added in addition to base styles output by the component. | |
| disabled | Boolean | Specifies whether the component should be displayed in a disabled state. Default value is "false". | |
| displayDatePicker | Boolean | Indicate if ui:datePicker is displayed. | |
| format | String | The java.text.SimpleDateFormat style format string. | |
| label | String | The text of the label component | |
| labelClass | String | The CSS class of the label component | |
| langLocale | String | The language locale used to format date time. | |
| required | Boolean | Specifies whether the input is required. Default value is "false". | |
| requiredIndicatorClass | String | The CSS class of the required indicator component | |
| updateOn | String | Updates the component's value binding if the updateOn attribute is set to the handled event. Default value is "change". | |
| value | Date | The input value of the date/time. |
Events
| Event Name | Event Type | Description |
|---|---|---|
| mouseup | COMPONENT | Indicates that the user has released the mouse button. |
| mousedown | COMPONENT | Indicates that the user has pressed a mouse key. |
| mousemove | COMPONENT | Indicates that the user has moved the mouse pointer. |
| dblclick | COMPONENT | Indicates that a component has been double-clicked. |
| mouseout | COMPONENT | Indicates that the user has moved the mouse pointer away from the component. |
| click | COMPONENT | Indicates that a component has been clicked. |
| mouseover | COMPONENT | Indicates that the user has moved the mouse pointer over the component. |
| keyup | COMPONENT | Indicates that the user has released a keyboard key. |
| keypress | COMPONENT | Indicates that the user has pressed and held down a keyboard key. |
| select | COMPONENT | Indicates that the user has made a selection. |
| keydown | COMPONENT | Indicates that the user has pressed and released a keyboard key. |
| focus | COMPONENT | Indicates that a component has been put on focus. |
| blur | COMPONENT | Indicates that a component has been put out of focus. |
| validationError | COMPONENT | Indicates that the component has validation error(s). |
| paste | COMPONENT | Indicates that the user has pasted content from the clipboard. |
| change | COMPONENT | Indicates that the content of a component or the state has changed. |
| clearErrors | COMPONENT | Indicates that any validation error should be cleared. |
| cut | COMPONENT | Indicates that the user has cut content to the clipboard. |
| copy | COMPONENT | Indicates that the user has copied content to the clipboard. |