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

Kendo DatePicker value(), class Issue

1 Answer 190 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Mauro
Top achievements
Rank 1
Mauro asked on 21 Aug 2013, 09:25 AM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 22 Aug 2013, 07:48 AM
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!
Tags
Date/Time Pickers
Asked by
Mauro
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or