how to close p:dialog on ESC key

UI Components for JSF
User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

17 Jul 2012, 10:13

AFAIK, this issue there is in the issue tracker and will be fixed in the future.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

csotolani
Posts: 4
Joined: 17 Jul 2012, 00:09

25 Jul 2012, 17:43

<script type="text/javascript">
jQuery(document).keyup(function(e) {
if (e.keyCode == 27) { //esc
closeOnEscape();
}
});
</script>

martib
Posts: 38
Joined: 28 Dec 2011, 14:58
Location: Switzerland

08 Aug 2012, 09:43

works create, now.

Did it like this:

Code: Select all

jQuery(document).keyup(function(keyPressEvent) {
    // evaluate key code
    var key = keyPressEvent.keyCode ? keyPressEvent.keyCode : keyPressEvent.which ? keyPressEvent.which : keyPressEvent.charCode;
    if (key == 27) { //escape
        closeOnEscape(); 
    }
});
function closeOnEscape() {
    var closeable;
    var indexHighest = 0;   
    jQuery(".ui-dialog.ui-widget.ui-widget-content.ui-overlay-visible").each(function() {
        var indexCurrent = parseInt($(this).css("zIndex"), 10);
        if (indexCurrent > indexHighest) {
            indexHighest = indexCurrent;
            closeable = this;
        }
    });   

    if (closeable != null) {
        jQuery(closeable).removeClass('ui-overlay-visible').addClass('ui-overlay-hidden');
        jQuery(closeable).css({'visibility':'', 'z-index':'', 'display':''});
        var modal = '#' + jQuery(closeable).attr('id') + '_modal';
        jQuery(modal).remove();
    }
}
PF 6.x, Weblogic 12c, JDK8, NetBeans 8.x

Ironhide2012
Posts: 62
Joined: 03 Aug 2012, 21:01

18 Sep 2012, 15:29

Any update on this? I just tried it and in the latest version it seems to still be an issue, thanks

martib
Posts: 38
Joined: 28 Dec 2011, 14:58
Location: Switzerland

19 Sep 2012, 06:53

use the the jquery sample above.
Issue is under http://code.google.com/p/primefaces/iss ... il?id=4209, but still not implemented
PF 6.x, Weblogic 12c, JDK8, NetBeans 8.x

elciospy
Posts: 3
Joined: 23 Aug 2012, 19:15

09 Oct 2012, 21:03

these sample above didn't work with <p:confirmDialog> :(

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

12 Nov 2012, 16:58

closeOnEscape will be available in 3.5. Implemented in trunk as of today.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests