Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close KendoUI modal window when click on overlay outside window?

I have Kendo UI modal window opened and I want to close it by clicking on overlay. How can I do that?

like image 392
user1762608 Avatar asked Jan 14 '14 08:01

user1762608


People also ask

How do I close kendo Windows?

Basically you already know how to close the window - you need to do it with the close method of its API. $("#window"). data("kendoWindow"). close();

How do I close a kendo dialog?

Code to close:data("kendoWindow"); wnd. close();


3 Answers

Try something like this:

var dialog = $("#dialog2").kendoWindow({
    modal: true
}).data("kendoWindow").center();

$(document).on("click", ".k-overlay", function () {
    dialog.close();
});

(demo)

like image 122
Lars Höppner Avatar answered Nov 01 '22 06:11

Lars Höppner


If you want to apply this to all kendo windows without having to have the variable that contains the instance handy you can do it like this:

    $(document).on('click', '.k-overlay', function () {
        var kendoWindow = $('.k-window-content.k-content', $(this).next('div.k-widget.k-window'));
        if (kendoWindow == null || kendoWindow.length == 0) {
            return;
        }
        kendoWindow.data('kendoWindow').close();
    });
like image 8
Sgraffite Avatar answered Nov 01 '22 08:11

Sgraffite


The previous answers did not work for me. Apparently newer versions of kendo do not generate the overlay until after the window is activated. So adding a click event failed because the .k-overlay class could not be found in the DOM. The solution was to add the event once the window is finished animating. I used jQuery to add the event listener since kendo uses jQuery.

var myWindow = $('#myWindow').kendoWindow({
    width: "310px",
    actions: [],
    visible: false,
    modal: true,
    title: "This is my title",
    activate: function() {
        // Close window when clicked outside of window
        $(".k-overlay").on("click",
            function() {
                myWindow.close();
            });
    }
}).data("kendoWindow");
like image 2
gsxrboy73 Avatar answered Nov 01 '22 06:11

gsxrboy73