Date validation failing but not sure why

5 posts, 0 answers
  1. Glenn
    Glenn avatar
    16 posts
    Member since:
    Sep 2007

    Posted 22 Jan 2014 Link to this post

    Hi there

    The customer is asking for date/time formats such as 01 Jun 2014 10:20

    So I specify this in the view:

    @(Html.Kendo().DateTimePickerFor(m => m.Baby.DateOfBirth).Format("dd MMM yyyy HH:mm").TimeFormat("HH:mm").HtmlAttributes(new { style = "width:170px"}).Max(DateTime.Now)))

    and this in the model:

    public DateTime? DateOfBirth { get; set; }

    Now when I select a date and time from the datepicker I see the value: "09 Jan 2014 02:00" which seems fine, but when I tab off I get the error " The field Date of Birth must be a date."

    Any idea why?
  2. Glenn
    Glenn avatar
    16 posts
    Member since:
    Sep 2007

    Posted 23 Jan 2014 Link to this post

    Also there seems to be a bug with the control.

    When I first show the page, I click the time button on the control to drop down the time-selection.  This initially lists a full list of times from 00:00 to 23:30.

    It's 11:18am here at the moment.  If I select 23:00 from the  list, the time entered into the value box isn't 23:00 but 11:00.

    And then when I select the time drop down again, the time dropdown doesn't list the full day now, it lists 00:00 to 11:00am and then the final value is 11:18am.
  3. Kendo UI is VS 2017 Ready
  4. Daniel
    Admin
    Daniel avatar
    2118 posts

    Posted 24 Jan 2014 Link to this post

    Hello Glenn,

    Which validator are you using? The problem  occur because the custom format is not recognized as valid. If you are using the jQuery Validation then you should override the validator date method so that it uses the custom format. If you are using the Kendo Validator then you should either override the mvcdate rule or use a culture script file in which the format is included. Note that the MVC DefaultModelBinder uses the current .NET culture formats to parse the date so in both cases it  might be necessary to register a custom ModelBinder in order to avoid a ModelState error on the server.

    The behavior of the timepicker is expected because the Max date is set to the current date and time 
    .Max(DateTime.Now)
    and so the selection will be limitted to the  current time.


    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Glenn
    Glenn avatar
    16 posts
    Member since:
    Sep 2007

    Posted 24 Jan 2014 Link to this post

    I'll try out your first suggestion, thanks.

    As for the date bug, yes the intention is to restrict the time dropdown to the current time, the BUG is that initially it is NOT restricting it until you select your first time.  And selecting the time doesn't work the first time as I said in the bug above.  I suspect the two things are related but there is definitely a problem there....  It might well be that this is all related to the DD/MMM/YYYY format....
  6. Glenn
    Glenn avatar
    16 posts
    Member since:
    Sep 2007

    Posted 25 Jan 2014 in reply to Glenn Link to this post

    Scratch that - after thinking it through I kinda realised why it's working the way it is.
    I need to sleep more...
Back to Top
Kendo UI is VS 2017 Ready