The field must be a date

10 posts, 0 answers
  1. Man
    Man avatar
    48 posts
    Member since:
    Sep 2015

    Posted 28 Sep 2015 Link to this post

    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. 

  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 30 Sep 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Man
    Man avatar
    48 posts
    Member since:
    Sep 2015

    Posted 30 Sep 2015 in reply to Daniel Link to this post

    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?

  5. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 02 Oct 2015 Link to this post

    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!
     
  6. Man
    Man avatar
    48 posts
    Member since:
    Sep 2015

    Posted 02 Oct 2015 in reply to Daniel Link to this post

    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. 

  7. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 06 Oct 2015 Link to this post

    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!
     
  8. Man
    Man avatar
    48 posts
    Member since:
    Sep 2015

    Posted 13 Oct 2015 Link to this post

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

     

  9. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 15 Oct 2015 Link to this post

    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!
     
  10. Man
    Man avatar
    48 posts
    Member since:
    Sep 2015

    Posted 15 Oct 2015 in reply to Daniel Link to this post

    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 

     

     

     

  11. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 19 Oct 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready