5

I'm working on some Salesforce lightning components and I need a nice DateTime control. The component reference lists the ui:inputDateTime control and this control supports the functionality, but it sure doesn't look like the control in Salesforce!

Here's what you get in SF experience:

enter image description here

And here's what you get out of the box with the ui:inputDateTime control:

enter image description here

The calendar itself is way too large and just isn't styled, and the Time control isn't even displaying the right icon. Here's my markup:

<div class="slds-form-element">
    <div class="slds-form-element__control">      
        <ui:inputDateTime aura:id="encStart" 
                          label="Start Time" 
                          value="{!v.newEvent.startTime}" 
                          displayDatePicker="true" /> 

    </div>
</div>

Am I just missing or just mis-applying a SLDS tag here? Any advice would be appreciated. Thanks.

S Walsh
  • 193
  • 4
  • Possible dupe of: http://salesforce.stackexchange.com/questions/134371/uiinputdatetime-date-and-time-pickers-not-displaying-properly – Jake Richter Dec 18 '16 at 12:55
  • Hi @JakeRichter, I don't think this is a duplicate of the one you mentioned. This asks specifically the reason for the difference and the OP is very specific too. – SE_User Dec 19 '16 at 04:44

2 Answers2

3

I believe the second picture is from a standalone application. If you place you component inside Salesforce lightning ui via app page/record page, it will work perfectly with same look and feel as native date picker.

In standalone apps, the Salesforce fonts are not loaded and you are viewing it in Helvetica font.

manjit5190
  • 8,023
  • 16
  • 33
1

I can't help with the time component, but I have built a custom date picker that you might like:

You can get it on github:

Unfortunately, there is a bit too much code to really try to explain how it works here, so I'll just post a pic:

Datepicker gif

How to use:

Assuming you are using an Opportunity (obviously any object with a date would work), define the Opportunity as an attribute on your component:

<aura:attribute name="opportunity" type="Opportunity"  />

In your form, put the below(once you have created it) as a top level member of the form. Note the handling of the dateChangeEvent in the markup

<div class="slds-form-element slds-m-top--medium">
  <c:DatePicker aura:id="closeDate" label="Close Date" 
                placeholder="Enter a Date" 
                value="{!v.opportunity.CloseDate}" 
                formatSpecifier="MM/dd/yyyy" 
                dateChangeEvent={!c.handleDateChange}
 />
</div>

Finally, in your controller or helper update your date:

handleDateChange: function(cmp, event, helper) {
  var dateSelector = event.getSource().getLocalId();
  opp.CloseDate = event.getParam("value");
  ....
}
Caspar Harmer
  • 20,414
  • 4
  • 33
  • 68