0

I am presently using the following command to select date by the datepicker:-

<ui:inputDate aura:id="startdate" format="MM/DD/YYYY" class="field" value="{!v.StartDate}" displayDatePicker="true" />

My requirement is to set a limit to the datepicker upto a year's data.

How do I set a limit to the datepicker to ensure that the user is not allowed to pick a date past the present date - 365 days?

  • 1
    You can write a validation which will check date range and if it does fall in the date range throw error. – MIX DML Feb 12 at 11:21
  • Have you tried anything? – Jayant Das Feb 12 at 13:42
  • Yes I used the controller to set a limit... – Rivu Indra Feb 13 at 6:25
  • Why not use lightning:input type date with mix, max? It disables of out of range dates as well. – Murali Pamidi Feb 13 at 7:22
0
var searchStartDate = component.get("v.StartDate");

    var result = new Date();
    result.setDate(result.getDate() - 365);
    var today = $A.localizationService.formatDate(result, "yyyy-MM-dd");

    if(searchStartDate<today){
        alert('The start date cannot be less than a year from the current date ');
        component.set("v.searchStartDate", null);}

This is the piece of code in controller to set a limit to the datepicker..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.