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?

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

1 Answer 1

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..

You must log in to answer this question.

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