This is a migrated thread and some comments may be shown as answers.

min date in DatePicker

3 Answers 296 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Neeraj
Top achievements
Rank 1
Veteran
Neeraj asked on 09 Oct 2018, 10:37 AM

 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

 

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 11 Oct 2018, 10:27 AM
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.
0
Neeraj
Top achievements
Rank 1
Veteran
answered on 29 Oct 2018, 05:35 AM
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. 
0
Konstantin Dikov
Telerik team
answered on 30 Oct 2018, 02:28 PM
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.
Tags
MVVM
Asked by
Neeraj
Top achievements
Rank 1
Veteran
Answers by
Konstantin Dikov
Telerik team
Neeraj
Top achievements
Rank 1
Veteran
Share this question
or