用closeOnEscape对多个对话框进行Primefaces



我有两个带有closeOnEscape="true"的对话框(A和B(。

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

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

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

这是一个错误,已报告给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();
}
};
});
}
};
}

最新更新