# Best-Practice for closing 'This Popup'?

**URL:** <https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [October 6, 2022, 3:54pm UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904 "2022-10-06T15:54:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [October 6, 2022, 3:54pm UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/1 "2022-10-06T15:54:28Z")

</div>

Ignition 8.1.20, Perspective:  
I'm curious what the _best practice_ is for closing the respective popup which contains a 'Close Popup' button? ...if a popupId is not known? ...if the 'Close Popup' button exists within an Embedded View of that popup?

Per insight from link below, we are using a script action within onActionPerformed of a Button object.

```auto
def runAction(self, event):
	system.perspective.closePopup('')

```

> [@self.page.props.pageId not resolving correctly?](https://forum.inductiveautomation.com/t/self-page-props-pageid-not-resolving-correctly/35664/5):
>
> Ah, okay, so the likely cause for what you’re encountering is a fix that went into 8.0.13. Before 8.0.13, if closePopup or togglePopup was supplied an id argument which didn’t match any open popup, then Perspective closed the most recently focused Popup. In the event self.page.props.pageId did not match the id of the popup you had open, but that popup was the most recently focused popup, it still would have been closed. Many users limped along on this bug without realizing it because most user…

Is it desirable to name the popup Id during closing? If so, is there a clean method of grabbing the popup's Id property?

Perhaps another question would be: What is the specific action that is performed when the built-in "X" is pressed (located in title bar, when 'Show close button' is selected on popup creation)?

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [October 6, 2022, 4:34pm UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/2 "2022-10-06T16:34:33Z")

</div>

I forgot to mention, there is an issue with the aforementioned script we are using, whereby the 'Active Popup' closes instead of the parent popup containing the button.  
This issue rears its ugly head only when multiple popups are open, and when the user clicks quickly on the close button of an inactive popup.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 6, 2022, 5:20pm UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/3 "2022-10-06T17:20:52Z")

</div>

The native `X` button of the Popup does not care about the ID - that's the browser operating on HTML components without regard for their content. If you want Perspective to operate on a Popup, you really need to provide the ID of the Popup. I recommend that every time you open a Popup you do so one of two ways:

1. Using a Script Action or Popup Action, pass the identifier used for the Popup as a param to the View. Then from within the View, any Button should reference that `id` param of the View. If you need to have your "close" button in an Embedded View of _this_ View, then you need to continue passing the param down the chain. This is the best approach because No View is responsible for hanging onto some ID that might be changed elsewhere.

```auto
popup_id = "ASDF"
system.perspective.openPopup(id=popup_id, view="MyView", params={"id": popup_id})

```

1. Hard-code the Popup ID into the View being used. This is a bad approach, but it will work until you change the ID in one location or the other.

---

<div class="post-metadata">

**Author:** ![david.gillbee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david.gillbee/32/27863_2.png) [@david.gillbee](https://forum.inductiveautomation.com/u/david.gillbee)\
**Post date:** [January 20, 2023, 3:27am UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/4 "2023-01-20T03:27:06Z")

</div>

Are there any updates planned that will enable a popupclose(self) feature?  
I have implemented the workaround of passing the popup id into the popup as a parameter however I am getting problems when people implement standard popupclose('') in my project.

I nice solution would be to add to the popup component a property naming the specific popup id.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 20, 2023, 5:57am UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/5 "2023-01-20T05:57:59Z")

</div>

No, because Views (and by extension their children) have no idea they are even in a Popup. Views are - for the most part - not very intelligent and only know about the Page they exist on because they understand they _must_ exist on a Page and therefore have access to page properties. There's no such guarantee any View belong to a Popup, or a Docked View.

Even if we opted to create a new function along the lines of `system.perspective.closeWhateverPopupILiveIn()`, There could be instances where it's invoked by a component that doesn't live in a page. Is the function idempotent when invoked within a View which is not in a Popup? The abstraction I mentioned earlier where Popups don't know much about how they fit in the grander scheme holds true for Embedded Views as well, and so how would this function work nested one, two, or N levels deep inside a View?

> [@david.gillbee](#):
>
> nice solution would be to add to the popup component

There is no Popup "component", but I'll assume you just meant to the Popup concept or mechanism. How would the View rendered for the Popup access this "injected" property? We'd have to have some sort of mechanism for the Popup to expose its ID to the View which will be rendered within. Something like... you guessed it: View params.

---

<div class="post-metadata">

**Author:** ![just\_use\_stats](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/just_use_stats/32/52665_2.png) [@just\_use\_stats](https://forum.inductiveautomation.com/u/just_use_stats)\
**Post date:** [September 26, 2023, 4:16am UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/6 "2023-09-26T04:16:21Z")

</div>

Couldn't ignition just sort of handle this for you?  
In some sense, a view COULD know it's been opened as a popup... because on creation it was created by a popup action or a script system.perspective.openPopup() call.  
Ignition could pass a flag to the view marking it as a popup.  
Then, if it's ever called to system.perspective.closeSelf(), it checks its is\_popup flag, and if true, closes itself (presumably the id is known behind the scenes). If it doesn't have the flag, the function does nothing.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 26, 2023, 7:36am UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/7 "2023-09-26T07:36:12Z")

</div>

Or, you pass the popup id as a parameter to the view, then use that id to close the popup. It's hardly more complicated than having more built-in functions. I don't think we need IA to hold our hand on this.

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [October 3, 2023, 8:33pm UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/8 "2023-10-03T20:33:27Z")

</div>

Which works **perfectly**...when all Designers are aware of this feature / limitation, and it is correctly implemented. It's not an issue that rears its ugly head until a power-user shows up (opens/closes multiple popups) and starts asking questions. Often, the closePopup('') button passes the initial test, & popup is deployed...

The software architecture matters here... but happens to be different from nearly every other HMI platform out there. I'm happy with the proposed solution, but also believe it's a reasonable (& minor) grievance.

Conveniently, an update was made which might alleviate some headaches on this topic: from [Ignition 8.1.30 Release Notes](https://inductiveautomation.com/downloads/releasenotes/8.1.30):  
"Fixed an issue that was causing the last opened popup to be closed instead of the top most popup when `system.perspective.closePopup` is called with an empty string passed in as the popup ID."

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 4, 2023, 7:01am UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/9 "2023-10-04T07:01:00Z")

</div>

That's not an issue if you pass the id though.

I understand that it might not be the way other platforms do it, but I'm pretty sure we love Ignition for what it does differently. Would we want IA to change direction and start copying others ?  
In this particular case, maybe concurrent platforms offer a `self.close` built-in function. But are the possibilities of their popups as vast as what ignition allows ? Is passing an id to the popup to have complete control over it too high a price ? I'm fine with it and I'm sure most people here will agree with this.

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [October 4, 2023, 6:43pm UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/10 "2023-10-04T18:43:58Z")

</div>

> [@pascal.fragnoud](#):
>
> Is passing an id to the popup to have complete control over it too high a price ?

😕 A feature regression is **not at all** on my want-list.  
On the contrary, I prefer to take advantage of the named popups, especially with Toggle Popup. Zero complaints there...  
To be clear, what I'd **like** is:

1. system.perspective.closePopup('SomePopupId') to continue to operate exactly as it does. Close the popup with Id that is passed to the function.

2. system.perspective.closePopup('') to either:  
a) Close 'THIS' popup (note that this works much better as of 8.1.30). Have the function work the same way as the 'X' close popup button does. Well, because, what else would you expect it to do? 🤔  
b) Have no effect at all. Remove the limitation and force designers to pass a popup Id in order to close the popup. This, to me, is preferrable than inadvertent closing of the wrong popup.

Since neither (a, b) are likely to happen. I'm content with the solution in this thread.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [October 4, 2023, 6:56pm UTC](https://forum.inductiveautomation.com/t/best-practice-for-closing-this-popup/64904/11 "2023-10-04T18:56:45Z")

</div>

For best results, post your ideas here,

> **[Inductive Automation Feedback](https://ideas.inductiveautomation.com/)**
>
> Give feedback to the Inductive Automation team so we can make more informed product decisions. Powered by Canny.
