Kendo DatePicker value(), class Issue

2 posts, 1 answers
  1. Mauro
    Mauro avatar
    4 posts
    Member since:
    Jun 2013

    Posted 21 Aug 2013 Link to this post

    Hi to everyone.
    I have an MVC view with a Kendo DatePicker
    @(Html.Kendo().DatePicker()
                            .Name("myDataPicker")       
                            .Value(DateTime.Now.Date)
                            .Format("dd/MM/yyyy")
                            .HtmlAttributes(new  {style = "width: 150px;" })
                        )


    I need to change the date of my element from javascript, and I'm doing it in this way
     $("#myDataPicker").kendoDatePicker({
                    value: new Date(),        
                    format: "dd/MM/yyyy", ( I have to do this because it doesn't remember the given format in the helper )
                });

    It works but this function changes some style in the element, in particular in the first span
    k-input is added causing a padding issue and style has now a width:100%, not 150px as I set in the helper and I have when the page is just opened
    so before
    <span class="k-widget k-datepicker k-header" style="width: 150px;">
    after
    <span class="k-widget k-datepicker k-header k-input" style="width: 100%;">

    I have to use an ugly workaround changing the class and style from jquery but I was wondering if there is a better solution

    any help is appreciated
    thank's
    Mauro
  2. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 22 Aug 2013 Link to this post

    Hello Mauro,

     
    In general, the Kendo widgets are designed to be initialized only once. Any subsequent initializations will modify the html and styling. 
    In order to change the value of the widget after its initialization, you will need to get the instance of the client object and use the value method.

    Regards,
    Georgi Krustev
    Telerik
    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