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.
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.
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...
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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With