Kendo UI DatePicker - getting the previous value

2019-07-07 03:01发布

问题:

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?

回答1:

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.



标签: kendo-ui