datepicker change event

2 Answers 4348 Views
Date/Time Pickers
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
Joshua asked on 05 Jul 2012, 10:20 PM
When i set the value for the datepicker programatically, the change event does not fire. The basic code is below:



                $("#datePicker").kendoDatePicker({
                    change: function (e) {
                        selectedDate = $("#datePicker").data("kendoDatePicker").value();
                        console.warn(selectedDate);
                    }
                });
$("#datePicker").data("kendoDatePicker").value(selectedDate);

2 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 09 Jul 2012, 01:28 PM
Hi Joshua,

By design, the DatePicker does not raise the change event when the value is set programmatically - it raises only if the date is modified by the end-user. In case you need to trigger the change event, you can use jQuery trigger(). For example:   
var datePicker = $("#datepicker").data("kendoDatePicker");
datePicker.value("01/01/2001");
datePicker.trigger("change");

I hope this helps.
 

Regards,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
commented on 11 Sep 2012, 09:40 PM

OK, so I went around this initially, but now that I am using mvvm it is a bit of a problem.

I would like to update my viewmodel and have it change the datepicker as expected.

You say this is by design. What situation is it trying to solve?

This is the ideal code I am trying to make work: http://jsfiddle.net/grippstick/d6TLu/ 

I have tried different version where i bind to change event or i set the value for the date picker, but i can never get the previous month and next month buttons to update the screen appropriately.
0
Georgi Krustev
Telerik team
answered on 12 Sep 2012, 10:07 AM
Hello Joshua,

I answered the support ticket opened on the same subject. Here is a quote of the email:

As my colleague pointed out, the value method of the DatePicker (applicable to all input widgets) does not raise change event. The Kendo MVVM implementation, on the other hand, depends on the change event of the input elements. If you need to update the UI then you will need to use the MVVM methods and update the ViewModel, not the widgets. As you probably know the Date is passed by reference and just its modification may cause undesirable effects. I have modified your jsFiddle demo and now it works as expected. 

I will ask you to continue our conversation in the support thread in order to avoid any duplication.

All the best,
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!
Tags
Date/Time Pickers
Asked by
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Iliana Dyankova
Telerik team
Georgi Krustev
Telerik team
Share this question
or