Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Esc key on Kendo Window Popup

I am using KendoUI controls with JavaScript with MVC. I have a popup window create by "kendoWindow". its working fine, but when i press ESC key it will automatically close. I want to disable the ESC key so that window popup can be only closed by Cancel button or close button.

Here is my Kendo Window code.

 var  wndEditClient= $("#divEditClient")
        .kendoWindow({
            title: "Edit Client",
            modal: true,
            visible: false,
            resizable: false,
            width: 450,
            actions: ["Close"]
        }).data("kendoWindow");

wndEditClient.open();

Please Suggest.

I tried JavaScript keypress event and all that but does not work.

  $(document).bind("keypress", function (e) {      
        if (e.keyCode == 27) {
            e.preventDefault();
        }
    });

Tried this but not working.

like image 598
sagar43 Avatar asked Jun 27 '14 12:06

sagar43


1 Answers

Put this before including your first Kendo Window directive:

$(function () {
    kendo.ui.Window.fn._keydown = function (originalFn) {
        var KEY_ESC = 27;
        return function (e) {
            if (e.which !== KEY_ESC) {
                originalFn.call(this, e);
            }
        };
    }(kendo.ui.Window.fn._keydown);
});

(demo)

like image 111
Lars Höppner Avatar answered Oct 21 '22 04:10

Lars Höppner