min date in DatePicker

4 posts, 0 answers
  1. Neeraj
    Neeraj avatar
    135 posts
    Member since:
    May 2015

    Posted 09 Oct 2018 Link to this post

     Hello,
                I want to have MVVM DatePicker with Min Date. 

    I tried 2 methods:

    1) Using Open event :

    <input data-role="datetimepicker" data-format="dd-MMM-yyyy hh:mm:ss tt" required validationMessage="!" name="DepartureDate" class="DepartureDate" data-parse-formats="['dd-MMM-yyy','dd-MMM-yy','dd.MM.yyyy','dd.MMM.YYYY','dd.mm.yy','dd.MMM.yy','ddMMyyyy','ddMMyy','ddMM','ddMMM','dd-MM-yyyy hh:mm:ss' ]"
     data-bind="value: DepartureDateTime, events:{open: OnOpenAirRequestDatePicker}" data-min="#: new Date() #" />
                <span data-for='DepartureDate' class='validation'></span>

     

    This works when someone opens date icon to select date. If user directly write old date it takes as input until OPEN event is not triggered.

    2) Using data-min attribute:

    <input data-role="datetimepicker" data-format="dd-MMM-yyyy hh:mm:ss tt" data-min="#: new Date() #" required validationMessage="!" name="DepartureDate" class="DepartureDate" data-parse-formats="['dd-MMM-yyy','dd-MMM-yy','dd.MM.yyyy','dd.MMM.YYYY','dd.mm.yy','dd.MMM.yy','ddMMyyyy','ddMMyy','ddMM','ddMMM','dd-MM-yyyy hh:mm:ss' ]" data-bind="value: ArriveDepartDetails.DepartureDateTime, events:{open: OnOpenAirRequestDatePicker}" data-min="#: new Date() #" />
                <span data-for='DepartureDate' class='validation'></span>

     

    this works and value binds if value is future date , in case of old date then today , value doesnt bind. 

    I want to restrict user also from entering old dates directly without selecting

     

     

     

     

     

     

     

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 11 Oct 2018 Link to this post

    Hello Neeraj,

    The "min" property restricts the user from entering value prior to the min value and such values will not be bound to the widget. From my understanding, if the value must be a future date, this should also be applied to the existing value.

    If I have misunderstood the exact requirement, could you please provide a dojo example replicating the behavior and elaborate what is the exact result that you want to achieve:  

    Regards,
    Konstantin Dikov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Neeraj
    Neeraj avatar
    135 posts
    Member since:
    May 2015

    Posted 29 Oct 2018 Link to this post

    you understood correctly , and one more thing in case of edit record if date is previous date what will happen, will it get date ? My new record and edit record form are same and has same date-picker. 
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 30 Oct 2018 Link to this post

    Hello Neeraj,

    When the stored date in the model is before the date set in the "min" property of the DataPicker, the value will not be bound and the picker will remain empty. This could be tested in the following dojo example: 
    Hope this helps.


    Regards,
    Konstantin Dikov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top