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

Setting min value on datepicker initialisation messes with the default format string?

5 Answers 237 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Duane
Top achievements
Rank 1
Duane asked on 31 Mar 2012, 11:09 AM
I've setup a kendo datepicker with kendo mvvm binding as detailed below, and if I enable the "min" value during the datepicker initialisation, the bound date becomes of the format: "Sat Mar 31 2012 00:00:00 GMT+1000 (E. Australia Standard Time)", whereas if I remove the setting of the "Min" value, the format becomes "2012/03/31" which is what I expect it to do with the "min" value set.  

Is this a bug in kendo? Tested in latest chrome browser with kendo release 2012.1.322.

view code:
<div id="container">
<input id="dateFrom" class="datePicker" data-role="datepicker" data-bind="value: startDate"/>
</div>

javascript:
$(document).ready(function() {
var viewModel = kendo.observable({
startDate: new Date("2012/03/31") });
kendo.bind($("#container"), viewModel);


$(".datePicker").width(182).kendoDatePicker(
{
                                format: "yyyy/MM/dd",
min: new Date() // this line right here causing the format to change of the databound value
});
});

5 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 02 Apr 2012, 03:57 PM
Hello Duane,

Currently, when the value of the DatePicker widget is set to value out of range, the string representation of the value is displayed in the input element and the value of the widget is null. This jsFiddle shows the correct behavior. Could you please share why you need to set a value which is out of range and what should be desired behavior?

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Duane
Top achievements
Rank 1
answered on 02 Apr 2012, 07:49 PM
I don't actually need to set the value to something that is outside of the range in this case, it turns out that I misunderstood how javascript dates were working in this case (i.e. new Date() having both date and time of initialisation, so it was actually ahead of the start of the current day, and in effect setting it to be that value makes that current day unselectable in the datepicker).

I think when I saw in the demo code the datepicker's "value" being set to "new Date()" I thought I could do the same for min / max as needed, but evidently this is not the case.

Thanks for clearing that up for me.
0
Borys
Top achievements
Rank 1
answered on 08 Oct 2016, 04:22 PM

Hello, I have similar issue. 

We need to set min for date picker for the current date, but start date can be set to the older date.

Datepicker displays start date as a string. Is there way to work around this behavior?. 

 

0
Georgi Krustev
Telerik team
answered on 13 Oct 2016, 07:09 AM
Hello Borys,

The DatePicker will not display the value properly formatted if the passed value is not recognizable. This means that the string value cannot be parsed properly using the default parseFormats option:

http://docs.telerik.com/kendo-ui/api/javascript/ui/datepicker#configuration-parseFormats

Please define the proper parse formats to avoid the described behavior. If the problem still persists, could you provide a repro Dojo demo? This will help us to get a understanding of the case and provide up-to-the-point solution.

Regards,
Georgi Krustev
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
Borys
Top achievements
Rank 1
answered on 13 Oct 2016, 01:22 PM

I found answer in the other forum's post. Datepicker does not format start value properly if the start value is out of the range ( in my case before the "min" property). One of workarounds was to set/update min date at the open/navigate event.
Which is kind of annoying. 

 

Tags
Date/Time Pickers
Asked by
Duane
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Duane
Top achievements
Rank 1
Borys
Top achievements
Rank 1
Share this question
or