Problem with date format

6 posts, 0 answers
  1. Elliot
    Elliot avatar
    59 posts
    Member since:
    May 2012

    Posted 31 Mar Link to this post

    I have the following date picker:

    <input kendo-date-picker ng-model="incident.dateOfIncident" required k-format="'{{dateFormat}}'" k-max="today" />

    The dateFormat is set to "dd-MMM-yyyy".  When I display the value of {{incident.dateOfIncident}} it is showing as:

    "2016-03-09T05:00:00.000Z"

    but the date picker is blank.  Why? and how do I get it to display the date in the dateFormat?

    I have read on a different post about parseFormats but I cant seem to get it to work.  If I am in fact supposed to use parseFormats what format would I use?

  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 04 Apr Link to this post

    Hello Elliot,

    The AngularJS template will not be evaluated before widget's initialization. Hence, during initialization process the format is still not defined, which will result in incorrect behavior.

    You can find more details about the case here: The best solution in this case will be to use a k-options with predefined options that is coming from the model scope.

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Elliot
    Elliot avatar
    59 posts
    Member since:
    May 2012

    Posted 04 Apr Link to this post

    That doesnt seem to work unless I am doing something wrong.  Here is what I have:

    <input kendo-date-picker ng-model="incident.dateOfIncident" k-options="incidentDateOptions" required />

    and in the controller:

    $scope.incidentDateOptions = {
        format: "dd-MMM-yyyy",
        max: new Date()
    };

  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 06 Apr Link to this post

    Hello Elliot,

    I prepared a simple Dojo demo showing how to define the format option of the widget: Could you modify the demo showing the erroneous behavior?

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. Elliot
    Elliot avatar
    59 posts
    Member since:
    May 2012

    Posted 12 Apr Link to this post

    http://dojo.telerik.com/eXOJU/3

    Essentially all I did was replace your $scope.dateString = "05-Apr-2016"; with $scope.dateString = "2016-04-13T04:00:00.000Z"; which is how the date is received from the webapi as indicated in the original post.  With this date format nothing is appearing in the date picker.l

  7. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 14 Apr Link to this post

    Hello Elliot,

    Probably, I am missing something, but the widget works as expected on my end: If the problem still persists, I would suggest you set the parseFormats option, ensuring that the provided date string can be parsed correctly:
    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready