Closing popups when changing between pages

I'm trying to close popups generated on one view, when I change to another one. The procedure I'm using is generating an onShutdown Event on my view, with the following code:

def runAction(self):
	messageType = 'closepopups'
	system.perspective.sendMessage(messageType, scope="page")

Then, on my component, I configured a message handler called 'closepopups', with the following code:

def onMessageReceived(self, payload):
	id=self.props.params.idPopup
	system.perspective.closePopup(id)

as the popup id is passed via a parameter. I don't see any results in the popup closing, and I suspect it is due to the onShutdown not activating.

Welcome to the forum, Gabriel. Please see Wiki - how to post code on this forum and then edit your post to fix it.

The described setup worked for me. Could you please share how you're passing the param to the Popup in use?

Side note: you're shadowing a Python builtin function as a variable: id. I highly recommend you avoid using that variable name, along with names like int, list, or dict. These names all mean something in python and using them as variable names can make troubleshooting issues incredibly difficult.

Screenshot 2024-04-06 at 1.42.20 PM

1 Like

Thanks for your response. I think the problem is that I'm using different instances of a symbol as an embedded view. In each view of my project, I'm embedding a symbol such as a valve. Then every modification (name, popups, ...) is made to the symbol, and not each individual embedded view. I'm passing the param to the popup like this:

Then each embedded view has a different tag and a different idPopup (thanks for the variable name advice, I'm going to change that).

Two things:

  1. This sort of shows me what I was looking for, but what I was really hoping to see was what the value being passed might be. The fact that this scenario works for me but not you seems to suggest that something somewhere along your Popup ID passing route is not configured correctly. I highly recommend putting some temporary logging into your scripts so that you can troubleshoot
# place this in any script which writes/reads the idPopup param.
system.perspective.print("ID at point X: {0}".format(idPopupVariableNameHere))
  1. Verify you've supplied the param to the field correctly. The Action inputs have thrown many users for loops because it looks like the value is applied when it is not. Clear out your Identifier field, then re-select the prop to be used there, then click Apply/OK. The problem stems from users typing into the field then clicking elsewhere without pressing Enter or Tab to commit the value.