I feel like I must be missing something simple here…
I have a popup that is opened with scripting from a button on a page. In that popup, I can open another popup which is also given an id. If I close the original/parent popup, I want both the child and parent to close. I assumed using system.perspective.closePopup(id=‘popupid’) for each popup and providing the id would close them both but it just closes the one on top.
How would i go about closing both from the ‘parent’ popup?
I don’t think that’s going to work as you want. A quick check shows that you need to select Popup 1 before its Close button will respond to a click. That means your user will end up pressing the Popup 1 Close button twice.
Figure 1. The first click on Popup 1’s Close button switches the focus from Popup 2 to Popup 1.
I don’t think what you are designing is standard windows GUI so it might cause some confusion.
You could set the Modal and Background Dismissible behavior on both. Then the first click anywhere outside Popup 2 will dismiss that and a second click outside Popup 1 will close that.
Figure 2. “Close all” on Popup 2 will work as required (but is the opposite of what was asked for).
Figure 3. The “Close all” button needs two popup close actions. You’ll need the popup IDs.
I think what @jcoletti is wanting to do is just close the other popups automatically, which should work fine if you use
system.perspective.closePopup() if supply the id’s and run the script on the parent windows close event.
If you aren’t supplying an id when opening the popups they wont have one.
system.perspective.closePopup('') will work but it will close all of your popups that weren’t given an id.
Just as a word of warning, you also need to consider logical steps of the script and at what point the script might no longer exist. When you close a Popup, the instanced View and all of the inner components stop existing. If the script you are executing belongs to one of those components, the script will cease to exist as well.
- I have PopupA and PopupB open.
- PopupA has the following script on a button:
That second line will never execute because once PopupA is closed the View/components/scripts cease to exist and so the script is gone before it even attempts to close PopupB.
Thanks for all the feedback!
@josborn , @cmallonee. That is exactly what I’m attempting to do.
On popup1, I currently have the following on a button script:
Yet still, it closes popup2 but not popup1. After popup2 closes, I re-click the button and popup1 is closed so I assume it’s not an issue with the id I’ve given the popup.
Again, thanks for all the response!
I suspect that you’re not applying the ids to the popups like you believe yourself to be. Could you supply the relevant script code or Action where you’re opening these two popups?
The code in the main view in onActionPerformed script to open popup 1 is
system.perspective.openPopup(id="popup1",view='Core/Pages/Popups/Popup1', showCloseIcon = False, resizable = False)
Pretty much same code above is used in the ‘Open Popup2’ button in Popup1 view but the id is ‘popup2’ and the viewpath is to popup2 (see image below).
system.perspective.openPopup(id="popup2",view='Core/Pages/Popups/Popup2', showCloseIcon = False, resizable = False)
Then the close button on Popup1 is closing by the ids given.
I just verified the code is working exactly like I would expect it to in 8.1.16 given the conditions described so far:
- Popup1 exists and has an assigned id of “X”.
- Popup2 exists and has an assigned id of “Y”.
- Popup1 has a button which would close Popup2 (based on id) first and then close Popup1 (based on id).
What version of Ignition are you using?
Ugh, it does appear to be working. What is throwing me off is the focus/selection of the popup.
When I have both popups (X,Y) open and click the close button in X, it’s just selecting/re-focusing popup X and not actually performing the close action. Then clicking the button again once in focus is closing both popups. So functionally it’s working, but the popup selection/focus makes it appear as if it takes 2 clicks to close.
Okay. We do have an open ticket to remove the need to apply focus to the Popup before registering input/interactions, but no timeframe on that.
@cmallonee Thank you for your assistance!
modal (user can only interact with this popup) and/or overlay dismiss (clicking outside the popup closes the popup) might be usefull when opening (one of) the popups