Reputation: 815
I'm attempting to do a confirmation when a user changes a date using the date picker. Is it possible to get the previous value from the object model or will I need to roll my own?
Upvotes: 3
Views: 6230
Reputation: 40917
There is not (afaik) but you can implement it pretty easily as this:
var datePicker = $("#date").kendoDatePicker({
change: function (e) {
var prev = $(this).data("previous");
var ok = confirm("Previous value:" + prev + ". Do you want to change?");
if (ok) {
$(this).data("previous", this.value());
} else {
datePicker.value(prev);
}
}
}).data("kendoDatePicker");
$(datePicker).data("previous", "");
Where I save previous value and then asks for confirmation.
See it running here.
Same approach but different implementation:
var datePicker = $("#date").kendoDatePicker({
previous: "",
change : function (e) {
var prev = this.options.previous;
var ok = confirm("Previous value:" + prev + ". Do you want to change?");
if (ok) {
datePicker.options.previous = datePicker.value();
} else {
datePicker.value(prev);
}
}
}).data("kendoDatePicker");
Where I extend kendoDatePicker.options
object with a previous
field and then I update it when it changes.
Upvotes: 3