Search code examples
javascriptliferayyuiliferay-aui

Liferay 6.2 modal add callback on close


I need to excute a generic function (console.log) on closing (on hide) modal window created with this javascript code:

    YUI().ready(function(A) {
        YUI().use('aui-base','liferay-util-window', function(A) {
            Liferay.Util.Window.getWindow(
                {
                    title : title,
                    uri: url,
                    dialog: {
                        cache: false,
                        modal: true
                    }
                }
            ).on('hide', function() {
                  console.log("Modal closed")});

        });
    });

'url' and 'title' are two variables passing from code above.
It doesn't work.
Any suggestion?


Solution

  • This will not work until you set destroyOnHide dialog option to true.

    By default it is set to false, hence the popup will only be hidden.

    See below:

    YUI().ready(function(A) {
        YUI().use('aui-base','liferay-util-window', function(A) {
            Liferay.Util.Window.getWindow({
                title : title,
                uri: url,
                dialog: {
                    destroyOnHide: true,
                    cache: false,
                    modal: true
                }
            }).after('destroy', function(event) {
                    alert('DESTROY MODAL!');
            });
        });
    });
    

    Then you will be able to intercept destroy event with after() method as usual.