Inline editing doesn't work with Date fields, get a validation error

6 posts, 0 answers
  1. Patrick
    Patrick avatar
    34 posts
    Member since:
    Oct 2011

    Posted 31 Oct 2012 Link to this post

    I would like to use inline editing with KendoUI grids in an MVC context, but can't at the moment for any data containing Date fields, because whenever I click the Update button (whether after creating a new record, or editing an existing one), even if I haven't changed the date field, I get a validation error (e.g. if the field is DateOfBirth)

    "The field Date of Birth must be a date". (please see attached screenshot)

    The date format I am setting for the Grid is dd MMM yyyy (because this is unambigous, whereas e.g 04 06 2012 is ambiguous and could mean either 4 June 2012 or 6 April 2012) and my pc (Windows 8, running Visual Studio 2012) is set up with UK regional settings.

    (I have a support ticket set up for this, but no solution yet after 10 days), so am posting it here in case anyone else can help.

    NB It has been suggested that I set the culture to "en-GB" (which I have never had to do before, including lots of other [non inline editing] use of KendoUI grids), but it didn't resolve the problem.

    Thanks in advance for your help
  2. Patrick
    Patrick avatar
    34 posts
    Member since:
    Oct 2011

    Posted 07 Nov 2012 Link to this post

    To follow up: Telerik support did eventually find a solution, which was to add the following just before the end of the <head> section in Views/Shared/_Layout.cshtml:



        @*01 Nov 2012 added at Telerik's suggestion, this works on its own, in fact the relevant culture.min.js file does NOT seem to need to be included
        as shown below: things still work with it commented out *@
        @{
            var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
            }
    @*  This doesn't seem to be needed
          <script src="@Url.Content("~/Scripts/kendo/2012.2.913/cultures/kendo.culture." + culture + ".min.js")"></script>*@
        <script>
            kendo.culture("@culture");
            var culture = kendo.culture();
            culture.calendar.patterns.F = "dd MMM yyyy";
            </script>

    However, whilst this solved the immediate problem, there turns out to be a separate problem which the above doesn't solve!  If I edit a date to be 7 Nov 2012 and click Update, the date looks to be correct at 7 Nov 2012.  But when I refresh or return to the page, the date is shown as 11 July 2012 (i.e. the day and month have become interchanged!).  Similarly, if I enter a date of 31 Oct 2012, when I return to the page and try and edit the record, I get a validation error saying that 10/31/2012 is not a valid date!

    So far, using the KendoUI grids with date fields has been far from a pleasant experience, with much time wasted on solving problems that users shouldn't have to deal with, to be frank!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. DominionZA
    DominionZA avatar
    49 posts
    Member since:
    Jul 2007

    Posted 08 Apr 2013 Link to this post

    Did you ever find a solution to your date field problems in the grid?
    I have been struggling for close on 3 days now. Such a time waster trying to get something so simple working.
  5. Adam
    Adam avatar
    17 posts
    Member since:
    Jan 2009

    Posted 12 Sep 2014 Link to this post

    I currently have the same problem, but adding that code didn't solve it.
  6. Adam
    Adam avatar
    17 posts
    Member since:
    Jan 2009

    Posted 12 Sep 2014 Link to this post

    I forgot to change the version number, it works for me now


    <script src="@Url.Content("~/Scripts/kendo/2014.2.903/cultures/kendo.culture.en-AU.min.js")"></script>
        @{
            var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
        }
        <script>
            kendo.culture("@culture");
            var culture = kendo.culture();
            culture.calendar.patterns.F = "dd MMM yyyy";
        </script>
  7. Patrick
    Patrick avatar
    34 posts
    Member since:
    Oct 2011

    Posted 12 Sep 2014 in reply to Adam Link to this post

    Yes, you have to keep updating the version number when you upgrade for example.

    Glad it's working.  That and formatting in templates have caused me lots of frustration and wasted time - I've asked Telerik to please improve their documentation in the templates area and I think they said they will be doing so. 
Back to Top
UI for ASP.NET MVC is VS 2017 Ready