Disable Esc key on Kendo Window Popup
Asked Answered
P

1

5

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.

Phytology answered 27/6, 2014 at 12:8 Comment(0)
J
7

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)

Jaques answered 27/6, 2014 at 14:39 Comment(1)
Thank You. You save my Day :)Phytology

© 2022 - 2024 — McMap. All rights reserved.