I created a custom Lightning component called inputDateTimeCustom to encapsulate some tweaks to the ui:inputDateTime component. I wanted to set the default class values and fix the icon position. The problem is the date and time no longer display when the value attribute is set.
inputDateTimeCustom.cmp
<aura:component extends="ui:inputDateTime">
<aura:attribute name="class" type="String" default="slds-input" />
<aura:attribute name="labelClass" type="String" default="slds-form-element__label" />
<aura:attribute name="displayDatePicker" type="Boolean" default="true" />
</aura:component>
inputDateTimeCustom.css
.THIS .dateTime-inputDate {
position: relative;
}
.THIS .datePicker-openIcon {
position: absolute;
left: auto; /* IE doesn't support initial so use auto instead. */
left: initial; /* Reset the left value so it doesn't interfere with the right. */
top: 7px;
right: 13px;
}
.THIS .dateTime-inputTime {
position: relative;
}
.THIS .timePicker-openIcon {
position: absolute;
left: auto; /* IE doesn't support initial so use auto instead. */
left: initial;
top: 7px;
right: 13px;
}
When I try to use the component and bind its value attribute, nothing appears in the component. As a sanity check, I added a ui:inputDateTime component, and it displays the datetime value correctly.
<div class="slds-form-element">
<!-- The component appears with no value -->
<c:inputDateTimeCustom label="Start" value="{!v.StartDate}" />
<!-- But this works fine -->
<ui:inputDateTime label="Start" value="{!v.StartDate}" />
</div>
Can anyone tell me what I'm doing wrong?
EDIT:
Not surprisingly, switching to composition works. I'd like to be able to use the inheritance version though and avoid repeating the attribute definitions for label and value.
<aura:component>
<aura:attribute name="value" type="String" />
<aura:attribute name="label" type="String" />
<aura:attribute name="class" type="String" default="slds-input" />
<aura:attribute name="labelClass" type="String" default="slds-form-element__label" />
<aura:attribute name="displayDatePicker" type="Boolean" default="true" />
<ui:inputDateTime value="{!v.value}"
label="{!v.label}"
class="{!v.class}"
labelClass="{!v.labelClass}"
displayDatePicker="{!v.displayDatePicker}" />
</aura:component>