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

Date validation failing but not sure why

4 Answers 66 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Glenn
Top achievements
Rank 1
Glenn asked on 22 Jan 2014, 02:06 PM
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?

4 Answers, 1 is accepted

Sort by
0
Glenn
Top achievements
Rank 1
answered on 23 Jan 2014, 11:20 AM
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.
0
Daniel
Telerik team
answered on 24 Jan 2014, 11:55 AM
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!
0
Glenn
Top achievements
Rank 1
answered on 24 Jan 2014, 01:36 PM
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....
0
Glenn
Top achievements
Rank 1
answered on 25 Jan 2014, 08:03 PM
Scratch that - after thinking it through I kinda realised why it's working the way it is.
I need to sleep more...
Tags
Date/Time Pickers
Asked by
Glenn
Top achievements
Rank 1
Answers by
Glenn
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or