Kendo UI DatePicker - getting the previous value

自闭症网瘾萝莉.ら 提交于 2019-12-10 18:30:48

问题


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.



来源:https://stackoverflow.com/questions/16151446/kendo-ui-datepicker-getting-the-previous-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!