简体   繁体   中英

How to check if p:dialog is open?

I have implemented a pop up box on my webpage using

<p:dialog header="Value" widgetVar="confirmationCbxTxt" ..>

Now, I want to check whether this pop up box is open when clicking on a Button on my page. The code for my Button is

<p:commandButton value="#{label.close}" ajax="true" id="Close2" onclick="focuspopup();" />

Using the onclick function "onclick="focuspopup();" I want to check whether my pop up box is open on the screen. Could any one suggest the approach . I am thinking of using jquery inside my focuspopup() to test for open popup.

Client side API for PrimeFaces.widget.Dialog contains three methods, according to the PrimeFaces 5.2 User Guide (page 184):

  • show() Displays dialog.
  • hide() Closes dialog.
  • isVisible() Returns visibility as a boolean.

Use the last one to satisfy the requirements. For instance, add this in your focuspopup() function:

var open = PF('confirmationCbxTxt').isVisible();

Notes: For older PrimeFaces versions (5.1 and below), isVisible() does not exist so you need to replace it by

var open = PF('confirmationCbxTxt').jq.is(':visible'); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM