Disable Esc key on Kendo Window Popup

3 posts, 0 answers
  1. Sagar
    Sagar avatar
    2 posts
    Member since:
    Jun 2014

    Posted 27 Jun 2014 Link to this post

    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();
    I tried JavaScript keypress event and all that but does not work.

    $(document).bind("keypress", function (e) {     
           if (e.keyCode == 27) {
               e.preventDefault();
           }
       });
    Please Suggest.
  2. Sagar
    Sagar avatar
    2 posts
    Member since:
    Jun 2014

    Posted 28 Jun 2014 in reply to Sagar Link to this post

    I found my answer 

    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);
    });
    It perfectly works for me :)
  3. Peeter
    Peeter avatar
    1 posts
    Member since:
    Jul 2016

    Posted 21 Jul in reply to Sagar Link to this post

    Thanks Sagar, works for me!.
Back to Top