How to get the ids of all open popups? (to close them all)

I need to be able to close all open popups when the page is changed, so I need to be able to get a list of all of the open popup ids, but I'm struggling to find how I would do this.. help! :slight_smile:

Edit: I have a dodgy solution.. just call system.perspective.closePopup('') a number of times...

you could either manage a list of ids and then close them that way

or for each popup just have a message handler that is the same on all of them that runs system.perspective.closepopup for the id. you'd still likley have to put the popup id into each respective one

1 Like

I did find a relevant post I stumbled on in the past (hint: use a message handler).

Scroll up a few posts to find a version of your 'dodgy solution' :grinning_face_with_smiling_eyes:

The above aside, I do wish there was a built-in to retrieve information about all open popups (and their z-order) of a session.

Thanks for the replies.

It looks like it isn't possible without some management effort on my part which is susceptible to being forgotten, particularly if other devs are involved who simply aren't aware.

I'll keep my spam call of closePopup("") for now as this does work, it just feels wrong..

1 Like

I find the message option quite easy to implement, without requiring any special kind of management, all you need is a parameter with the popup's id.
Then popups are responsible for closing themselves when catching the message.
This gives you a lot of flexibility:

  • Don't implement the handler on a particular popup if it should stay open
  • Add some context to the message through the payload for conditional handling
1 Like

It's more that whenever a new popup is created, the person needs to know and remember to add the thing to it, I'd rather it just be inherent

You could make a wrapper function + view to streamline it. Though that's really not my favorite thing.

I do have a wrapper function to open popups, that generates an uuid and assigns it as the popup's id, but the wrapper view is... ugh

I do both of these already, the 2nd one kind of for device popups. I have a single popup that I use for all device types (motors/valves/analogues/etc) that has a standard set of tabs with some that hide based on device type. The tab contents for some of them are defined within separate Views, while other more standard tabs like trends, interlocks, alarms etc. are all defined within the popup itself. So I actually don't have a lot of popups.. but still :man_shrugging: