Search code examples
kendo-uikendo-datetimepicker

Kendo control datepicker doesn't understand dateformat in MVVM


I have the following code:

 <input data-role="datepicker" data-bind="value:referralData.Referral.from_date" />

With the value to bind as such:

from_date: "2014-01-01T00:00:00"

In the object and it doesn't bind anymore. I have tried:

       <input data-role="datepicker" data-bind="value:referralData.Referral.from_date, parseFormats:'YYYY-MM-DD\Thh:mm:ss'" />

But it states that: Uncaught Error: The parseFormats binding is not supported by the DatePicker widget. So I believe I have a syntax error that I am missing.

Does anyone know how to tell the datepicker to pick up this date?


Solution

  • The solution by @Lars works, but the date format specifier is wrong (as of Kendo version 2014.3.119). It should be yyyy-MM-ddTHH:mm:ss (lower case for year and day and upper case for hour):

    <input
        data-role="datepicker" 
        data-bind="value:referralData.Referral.from_date" 
        data-parse-formats="yyyy-MM-ddTHH:mm:ss" />
    

    And as a completion, if sometimes you need to, you can in fact pass more than one format, according to the documentation, like this:

    <input 
        data-role="datepicker" 
        data-bind="value:referralData.Referral.from_date" 
        data-parse-formats="['yyyy-MM-ddTHH:mm:ss','yyyy-MM-dd']" />