【问题标题】:Primefaces Multiple Dialogs with closeOnEscapePrimefaces 带有 closeOnEscape 的多个对话框
【发布时间】:2020-12-16 19:21:45
【问题描述】:

我有 2 个对话框(A 和 B)与 closeOnEscape="true"

两个对话框都是模态的,里面有<p:focus context="innerForm" />

对话框 A 打开对话框 B。是的,我知道,这是一个糟糕的设计,但是......

问题是,当我在对话框 B 上按 ESC 时,它会正确关闭并且焦点返回到对话框 A,但 ESC 不会关闭此对话框。

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    这是一个错误,已在 GitHub 上向 PrimeFaces 报告: https://github.com/primefaces/primefaces/issues/6677

    公关:https://github.com/primefaces/primefaces/pull/6678

    将在 PF 9.0 中

    将此添加到在 PF 之后加载的 JS 中以立即修复它:

    if (PrimeFaces.widget.Dialog) {
        PrimeFaces.widget.Dialog.prototype.bindEvents = function() {
            var $this = this;
    
            //Move dialog to top if target is not a trigger for a PrimeFaces overlay
            this.jq.on("mousedown", function(e) {
                if (!$(e.target).data('primefaces-overlay-target')) {
                    $this.moveToTop();
                }
            });
    
            this.icons.on('mouseover', function() {
                $(this).addClass('ui-state-hover');
            }).on('mouseout', function() {
                $(this).removeClass('ui-state-hover');
            }).on('focus', function() {
                $(this).addClass('ui-state-focus');
            }).on('blur', function() {
                $(this).removeClass('ui-state-focus');
            });
    
            this.closeIcon.on('click', function(e) {
                $this.hide();
                e.preventDefault();
            });
    
            this.maximizeIcon.on("click", function(e) {
                $this.toggleMaximize();
                e.preventDefault();
            });
    
            this.minimizeIcon.on("click", function(e) {
                $this.toggleMinimize();
                e.preventDefault();
            });
    
            if (this.cfg.closeOnEscape) {
                $(document).on('keydown.dialog_' + this.id, function(e) {
                    var keyCode = $.ui.keyCode;
                    if (e.which === keyCode.ESCAPE && $this.isVisible()) {
                        var active = parseInt($this.jq.css('z-index')) === parseInt($('.ui-dialog:visible').last().css('z-index'));
                        if (active) {
                            $this.hide();
                        }
                    };
                });
            }
        };
    }
    

    【讨论】:

    • 谢谢@Melloware,我可以申请任何解决方法吗?
    • 是的,让我把它贴在那张票和这里。
    猜你喜欢
    • 1970-01-01
    • 2014-02-15
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多