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

The field must be a date

9 Answers 1135 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Man
Top achievements
Rank 1
Man asked on 28 Sep 2015, 08:14 AM

I have added a date field using a datepicker as below

@(Html.Kendo().DatePickerFor(m => ​m.StartDate)
                            .Format("dd/MM/yyyy")
                            .ParseFormats(new List<string>()
                                          {
                                            "dd/MM/yyyy",
                                            "dd/MM/yy",
                                            "dd MMM yyyy"
                                           })
                            .HtmlAttributes(new { @class = "k-datetimepicker" }))​

 

 

However, on tabbing out, kendo ui datepicker throws an error "The field must be a date"

 

Can you please assist? I have seen a few other threads on the forum and tried other solutions like adding a script tag to set culture info but nothing seems to work. These solutions have not worked for everyone either. 

9 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Sep 2015, 07:58 AM
Hello,

The datepicker does not have its own validation. Which validator are you using? The Kendo Validator or the jQuery validation? If you are using the Kendo Validator then you should either use a Kendo culture that contains the format used for the datepicker or the approach demonstrated here. If you are using the jQuery validation then you should override the validator date method as demonstrated here.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Man
Top achievements
Rank 1
answered on 30 Sep 2015, 08:30 AM

Hi Daniel,

   Many thanks for your reply. I am using a custom validator for date comparison which compares 2 date fields (start and end date). 

Whilst, adding that extended date validation that you suggested worked in removing the error, the jquery version I am using on my solution is 2.1.4 but kendo uses 1.9.0

This causes the showerrors() of jquery to not show any errors even though it knows there is an error. Are there any potential issues with upgrading jquery within kendo to the latest version?

0
Daniel
Telerik team
answered on 02 Oct 2015, 08:23 AM
Hello again,

I am not sure if I understand the problem with showing the error messages but the combined Kendo script files do not include jQuery and all of the latest versions support jQuery 1.9.1+(including 1.10.x and 2.1.x) so yes, you could load only jQuery 2.1.4.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Man
Top achievements
Rank 1
answered on 02 Oct 2015, 01:28 PM

Hi Daniel,

   Many thanks for your reply. I am using unobtrusive javascript but for some reason it is not displaying the error

the .showerrors() comes back as undefined but the number of errors has got 1 error. A google search showed issues with jquery version. 

0
Daniel
Telerik team
answered on 06 Oct 2015, 10:51 AM
Hi,

Does changing the jQuery version makes a difference? Also, does the problem occur with the MVC built-in helpers or only with the datepicker? If the problem occurs only with the datepicker then could you provide a runnable sample that replicates it?

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Man
Top achievements
Rank 1
answered on 13 Oct 2015, 08:43 AM

It stops giving me the "Field must be a date" error but still no luck on the showerrors()

 

0
Daniel
Telerik team
answered on 15 Oct 2015, 07:44 AM
Hello,

I attached a sample project that uses validation for the datepicker. Please check it and let me know if I am missing something.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Man
Top achievements
Rank 1
answered on 15 Oct 2015, 09:12 AM

Hi Daniel,

   I have just compared the html using Chrome's inspector. 

 

My version shows - 

<input class="k-datetimepicker k-input" data-val="true" data-val-date="The field Start Date must be a date." data-val-required="The Start Date field is required." id="StartDate" name="StartDate" type="text" value="22/09/2015" data-role="datepicker" role="combobox" aria-expanded="false" aria-owns="StartDate_dateview" aria-disabled="false" aria-readonly="false" style="width: 100%;">

 

 

Your version shows  - 

<input class="k-datetimepicker k-input valid" data-val="true" data-val-date="The field MyDate must be a date." data-val-required="The MyDate field is required." id="MyDate" name="MyDate" type="text" data-role="datepicker" role="combobox" aria-expanded="false" aria-owns="MyDate_dateview" aria-disabled="false" aria-readonly="false" aria-activedescendant="a20333ae-299a-40ec-89c0-5eef78b51e0b_cell_selected" style="width: 100%;">

 

On first glance, the major difference is "valid" added to the class and a couple of other properties like aria-activedescendant ​. Not sure if this rings a bell 

 

 

 

0
Daniel
Telerik team
answered on 19 Oct 2015, 08:13 AM
Hello,

Unfortunately the differences do not indicate what could be causing the problem. If the validation is working correctly in the sample project then I will need a runnable sample that replicates the problem in order to investigate further.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Date/Time Pickers
Asked by
Man
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Man
Top achievements
Rank 1
Share this question
or