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

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

5 Answers 347 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Patrick asked on 31 Oct 2012, 02:14 PM
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

5 Answers, 1 is accepted

Sort by
1
Patrick
Top achievements
Rank 2
answered on 07 Nov 2012, 04:01 PM
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!
0
DominionZA
Top achievements
Rank 1
answered on 08 Apr 2013, 12:53 PM
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.
0
Informed Sources
Top achievements
Rank 1
answered on 12 Sep 2014, 05:22 AM
I currently have the same problem, but adding that code didn't solve it.
0
Informed Sources
Top achievements
Rank 1
answered on 12 Sep 2014, 05:43 AM
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>
0
Patrick
Top achievements
Rank 2
answered on 12 Sep 2014, 02:33 PM
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. 
Tags
Grid
Asked by
Patrick
Top achievements
Rank 2
Answers by
Patrick
Top achievements
Rank 2
DominionZA
Top achievements
Rank 1
Informed Sources
Top achievements
Rank 1
Share this question
or