0

I have as follows:

<aura:attribute name="todayDate" type="Date"/>
<lightning:input type="dateTime" aura:id="dat" label="Follow Up" min="{!v.todayDate}"/>

In the doInit event of the component I have as follows

component.set("v.todayDate",new Date());

But when the component loads user is able to select past dates also. Pls let me know where I am going wrong.

1 Answer 1

1

in your doInit function you have to set today date by using localization service for todayDate attribute.

like below cmp

 <aura:attribute name="todayDate" type="DateTime"/>

controller.js

 var timezone = $A.get("$Locale.timezone");
    var datetimestring =  new Date().toLocaleString("en-US", {timeZone: timezone}),
       datetime = new Date(datetimestring);
      datetime.setHours(datetime.getHours()+1);
    
    component.set('v.todayDate', datetime);

above solution works for me until summer20, after seen your comment i checked my project components all of them are broke. after all analysis what i found in summer20 release notes again. there is changes for lightning:input type=Date/datetime

The input types date and datetime have changed.

1.On the current month view of the date picker, you can now select a date from the previous and next month. Previously, dates from the previous and next month were disabled on the current month view unless you navigated directly to those months.

2.When you specify min and max values, users can still select a date outside of the min and max range. However, the blur event triggers the field to display a validation error message.

3.The names for months and weekdays in the date picker now use your Salesforce language setting. Previously, these names used your locale setting.

so in your case 2 point applied. that's why past dates are not disable. instead it giving the error. enter image description here

5
  • it is still showing the previous dates. Commented Jul 21, 2020 at 4:47
  • added updates with changes
    – sdandamud1
    Commented Jul 21, 2020 at 11:54
  • so salesforce upgrade is the issue , I have written a validation to handle this ,thanks for letting me know... Commented Jul 21, 2020 at 14:03
  • u don't need to write separate validation. if u set min/max it's fire automatically
    – sdandamud1
    Commented Jul 21, 2020 at 14:14
  • ok, ys I understood.. Commented Jul 21, 2020 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .