Forums

Home » Alloy UI » English

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
krishna mohan mathakala
Do not want to close aui dialogue on esc key press
February 1, 2016 9:53 PM
Answer

krishna mohan mathakala

Rank: Junior Member

Posts: 45

Join Date: September 7, 2012

Recent Posts

Hi


I am using aui dialogue ,I want to prevent closing dialog when esc key is pressed.
Or is there any way to trig a method when esc key is pressed.
Aui version is 2.0.
Kyle Joseph Stiemann
RE: Do not want to close aui dialogue on esc key press
February 2, 2016 7:40 AM
Answer

Kyle Joseph Stiemann

LIFERAY STAFF

Rank: Liferay Master

Posts: 526

Join Date: January 14, 2013

Recent Posts

Hi Krishna,

One way to do this is to listen for the ESC press and prevent the dialog from hiding:

Y.one('body').on('key', function(event) {
modal.once('visibleChange', function(event) {
// If the dialog was already visible, then keep it visible.
if (event.prevVal === true) {
event.newVal = true;
}
});
}, 'esc');


The above code attaches a one time visibleChange listener to the modal that ensures it will remain visible after ESC is pressed. Otherwise, the dialog can be hidden normally.

Here's a runnable JSBin with the code.

- Kyle
krishna mohan mathakala
RE: Do not want to close aui dialogue on esc key press
February 17, 2016 6:26 AM
Answer

krishna mohan mathakala

Rank: Junior Member

Posts: 45

Join Date: September 7, 2012

Recent Posts

Thanks Kyle Joseph Stiemann.

It worked for me .



 1
 2
 3var popUpWindow=Liferay.Util.Window.getWindow(
 4                            {
 5                                dialog: {
 6                                centered: true,
 7                                constrain2view: true,
 8                                //cssClass: 'yourCSSclassName',
 9                                modal: true,
10                                resizable: false,
11                                toolbars: false,
12                                width:500,
13                                height:380,
14                                }
15                            }
16
17
18A.one('body').on('key', function(event) {
19                                popUpWindow.once('visibleChange', function(event) {
20                                    if (event.prevVal === true) {
21                                        event.newVal = true;
22                            }
23                            });
24                            }, 'esc');
Mariappan K
RE: Do not want to close aui dialogue on esc key press
November 11, 2016 9:59 PM
Answer

Mariappan K

Rank: New Member

Posts: 4

Join Date: August 6, 2016

Recent Posts

Hi Krishna Mohan,
I was using this code. when I click the button the popupwindows is not opened . .
What I do

I attached my code. pls help me.
<aui:script use="liferay-util-window">
A.one('.generate-artform').on('click', function(event)
{
<!-- - alert("open"); -->
var popupWindow=Liferay.Util.openWindow({ dialog:
{
centered: true,
height: 2000,
modal: true,
width: 2000,
resizable: true
},
id: '<portlet:namespace/>dialog',
title: 'Art Information',
uri: '<%=generateArtFormURL %>'
}
);

A.one('body').on('key', function(event) {
popupWindow.once('visibleChange', function(event) {
// If the dialog was already visible, then keep it visible.
if (event.prevVal === true) {
event.newVal = false;
}
});
}, 'esc');
});
</aui:script>
Kyle Joseph Stiemann
RE: Do not want to close aui dialogue on esc key press
November 21, 2016 12:01 PM
Answer

Kyle Joseph Stiemann

LIFERAY STAFF

Rank: Liferay Master

Posts: 526

Join Date: January 14, 2013

Recent Posts

Hi Mariappan,
Could you post the shortest, simplest code needed to reproduce your issue? Please also include the version of Liferay and AlloyUI that you are using. Finally, please include any error messages that occur in the browser logs too.

- Kyle
Mariappan K
RE: Do not want to close aui dialogue on esc key press
December 9, 2016 5:42 AM
Answer

Mariappan K

Rank: New Member

Posts: 4

Join Date: August 6, 2016

Recent Posts

Hi Stiemann,
Thanks for Reply. I was using Liferay ui icon button. When I click the the button then popup window was opened. I was used the above code to open a popup window . and if I click the ESC button I don't want to close the popup window. and I am using Liferay 6.2 version. I can't see any error message in browser. may you help me.
-Mariappan
Kyle Joseph Stiemann
RE: Do not want to close aui dialogue on esc key press
December 22, 2016 2:42 PM
Answer

Kyle Joseph Stiemann

LIFERAY STAFF

Rank: Liferay Master

Posts: 526

Join Date: January 14, 2013

Recent Posts

I see a couple of problems with your code:

  1. You are creating a new pop up window and key handler every time you click the .generate-artform button:

    A.one('.generate-artform').on('click', function(event) {
    var popupWindow = Liferay.Util.openWindow({ /* ... */ });
    A.one('body').on('key', function(event) {
    // ...
    }, 'esc');
    });


  2. You are using html comments in your JavaScript:

    A.one('.generate-artform').on('click', function(event) {
    <!-- - alert("open"); -->
    // ...
    });



Instead what you should probably do is create the pop up once and attach the key handler once:

var popupWindow = null;

A.one('.generate-artform').on('click', function(event) {
// alert("open");

// Only create the pop up window once.
if (!popupWindow) {
popupWindow = Liferay.Util.openWindow({

dialog: {
centered: true,
height: 2000,
modal: true,
width: 2000,
resizable: true,
visible: true
},
id: '<portlet:namespace/>dialog',
title: 'Art Information',
uri: '<%=generateArtFormURL %>'
});

// Only create the key handler once.
A.one('body').on('key', function(event) {
popupWindow.once('visibleChange', function(event) {
// If the dialog was already visible, then keep it visible.
if (event.prevVal === true) {
event.newVal = false;
}
});
}, 'esc');
} else {
popupWindow.show();
}

});


This may or may not fix your issue, I would need to see the enclosing script markup and the .generate-artform button markup to be sure.

- Kyle