Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Raise the Change Event in the KendoUI DatePicker?

I'm trying to set the value of my DatePicker using the code below and expecting the "Change" event to be raise but it doesn't.

var datePicker = $("#datePicker").data("kendoDatePicker");
var previousDate = new Date(datePicker.value());
previousDate.setDate(previousDate.getDate() - 1);
$("#displayDate").text(kendo.toString(new Date(previousDate), 'D'));
datePicker.value(previousDate);

Change the date value through the user interface does raise the "Change" event as expected however.

like image 373
JeeShen Lee Avatar asked Mar 30 '13 08:03

JeeShen Lee


People also ask

How do I change date format in kendo DatePicker?

You can control the format of the DatePicker by using the format property. The component can be configured either to display a single format at all times, or to display the value in different formats when the input is focused or blurred.

How do I get rid of kendo DatePicker?

Every kendo widget have a destroy method that will clear all the support related to the widget. Once you've call the destroy method, you can empty the DOM element and you'll be able to recreate a new widget with that element if you need to. I forgot to mention...


1 Answers

Please try with the below code snippet.

HTML

<input id="datepicker" />
<input type="button" value="set date" onclick="setdateInDP()">

JS

<script type="text/javascript">
$(document).ready(function () {
    function onChange() {
        alert("Change :: " + kendo.toString(this.value(), 'd'));
    }

    $("#datepicker").kendoDatePicker({
        change: onChange
    });
});

function setdateInDP() {
    var datePicker = $("#datepicker").data("kendoDatePicker");
    var previousDate = new Date(datePicker.value());
    previousDate.setDate(previousDate.getDate() - 1);
    datePicker.value(previousDate);
    $("#datepicker").data("kendoDatePicker").trigger("change");
}

like image 200
Jayesh Goyani Avatar answered Sep 16 '22 16:09

Jayesh Goyani