Validation not working as expected

2 posts, 0 answers
  1. PaulMrozowski
    PaulMrozowski avatar
    80 posts
    Member since:
    Apr 2007

    Posted 17 Jul 2012 Link to this post

    I have a model that includes a DateTime field. It has a "[Required]" attribute on the property. My .cshtml file includes this:

    @(Html.Kendo()
        .DatePickerFor(p => p.CashReceipt.ReceivedOn)
        .HtmlAttributes(new { type = "text" })                                               
    )

    I'm not seeing the HTML attributes rendered into the output that I would expect, ex. data-val-required, etc.

    I copied over the EditorTemplates from the sample project, then created a clean page to help isolate the problem. Instead of using the above, I tried this:

    @Html.EditorFor(p => p.CashReceipt.ReceivedOn)

    When this page runs, I see the validation attributes in the HTML as expected, however the JS on the page fails with "Uncaught TypeError: Object [object Object] has no method 'kendoDateTimePicker' "

    I thought it might be because I have all of my JS references at the bottom of the page (to speed up page rendering), so I tested them at the top - I get the same error. 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script
    <script type="text/javascript" src="/Scripts/modernizr-1.7.min.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.validate.min.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.validate.unobtrusive.min.js"></script>
    <script type="text/javascript" src="/Scripts/knockout-2.0.0.js"></script>
    <script type="text/javascript" src="/Scripts/kendo.web.min.js"></script>
    <script type="text/javascript" src="/Scripts/kendo.aspnetmvc.min.js"></script>
    <script type="text/javascript" src="/Scripts/knockout-kendo.min.js"></script>


    So the big question is - how do I make this work? More specifically, how do I make this work without just hardcoding the attributes in via the HtmlAttributes() method?
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 20 Jul 2012 Link to this post

    Hello Paul,

     
    When try to render editor for property of nested model (CachReciept) the DatePicker will not render the validation attributes. This is a known issue and will be addressed in the next internal build of the KendoUI.
    As to the JavaScript error, I could not see where the jQuery JS file is included. Please note that the KendoUI has dependency to the jQuery.

    Regards,
    Georgi Krustev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top