javascript - 按 ESC 键关闭对话框时显示确认对话框

标签 javascript jquery primefaces dialog

我有一个对话框,如果我按ESC键,我想显示对话框确认(你确定吗?)此事件将触发p:commandButton。代码如下:

<p:dialog id="dlgEdit" closeOnEscape="false" closable="false" modal="true">
   ...
   ...
   ...
  <p:commandButton process="@this" value="SAVE" widgetVar="btnSaveDialogEdit">
    <p:confirm ...
               message="do you want save?"/>
  </p:commandButton>

  <p:commandButton process="@this" value="CLOSE" widgetVar="btnCloseDialogEdit">
    <p:confirm ...
               message="do you want close?"/>
  </p:commandButton>

  <p:confirmDialog>
  ...two commandbutton Yes/No
  <p:confirmDialog>

  <p:hotkey bind="esc" handler="PF('btnCloseDialogEdit').getJQ().click()" />
</p:dialog>

当我点击按钮SAVE时,对话框你想保存吗?显示,一旦我按下ESC键第二个对话框你想要关闭 显示吗?在确认对话框中,启用 closeOnEscape = "true"。我想,当我在对话框你想保存吗?上按ESC键时,这个对话框将被隐藏,但我不能。!!

最佳答案

您可以通过以下结构来实现:

<p:dialog id="dlgEdit" widgetVar="dlgEdit"
    closeOnEscape="true" closable="false" modal="true">
    ...
    ...
    ...

    <p:confirmDialog message="Do you want to save?" widgetVar="confirmClose">
        <p:commandButton value="Yes"
            oncomplete="PF('confirmClose').hide();PF('dlgEdit').hide();" />
        <p:commandButton value="No" type="button"
            onclick="PF('confirmClose').hide();PF('dlgEdit').hide();" />
    </p:confirmDialog>

    <p:hotkey bind="esc" handler="PF('confirmClose').show();" />
</p:dialog>

请记住为按钮添加您的监听器以处理保存机制。

关于javascript - 按 ESC 键关闭对话框时显示确认对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46885150/

相关文章:

javascript - ES6 模块导入文件组,单独导出

javascript - 如何在包括标点符号和特殊字符的范围内包装字母?

jquery - LINQ 和反射

php - $.getJSON 在某些浏览器中的问题

java - JSF-<h :commandButton> does not invoke new window from backing bean

javascript - 自动完成更新时如何调用JS函数

java - id更新组件的规则

javascript - 使用 Gridster.js 启用拖放

javascript - 管理与react-router react 的加载栏的状态

javascript - 使用 jQuery 在页面上提交 1 个 Ajax 表单,其中包含多个独特的表单