Displaying popups and passing data from them

Does anyone have a solution for displaying popups, passing data to them, and then passing data from them while closing the popup? I’ve tried literal popups and embedded views and can’t find a way to pass data back to the original view’s parameters.

Popups will not “pass” parameter values because they are independent of the Page/View which opened them (they remain open if you navigate somewhere else).

That being said, there are several ways to provide data present in a popup so that it may be consumed by something else (assuming these are values which are changing within the popup).

  1. bi-directionally bind the desired value in the popup to a custom session property. This will allow anything in your project to bind against that value. This does require that the property already be in place and therefore have a default value, and it will retain values for the life of the session, so not a great idea in some cases.
  2. place a propertyChange script on the relevant components, and use system.perspective.sendMessage() (docs) to essentially broadcast the new value to listeners. This obviously requires that you configure listeners for any property you need to “subscribe” to in the Popup, but it’s accurate and doesn’t persist like the session properties solution would.
  3. If you only need the data on Popup CLOSE, then if you make your own button to perform the close action you could bundle all of the data and broadcast a single message in the button’s onClick Event, something like the following code would work great, but also would require that you pass the Popup a unique ID when it gets opened. This method would allow for a single broadcast (sendMessage invocation) and single configured listener.
system.perspective.sendMessage(messageType='DATADUMP',payload={'name':self.root.getChild('NameTextField').props.text, 'user_id':self.root.getChild('UserIDNumericEntryField').props.value},scope='page')
system.perspective.closePopup(id=self.view.params.id)
1 Like

If you created a view (A) that is capable of opening popup (B) and embedded it in views (C) and (E), how could you ensure that when view (A) which is embedded in view (C) calls popup (B), view (A) which is embedded in view (E) does not receive the message sent by popup (B)?

My assumption is that view (A) would need to pass a unique identifier that is dependent on where it is embedded to popup (B), but I am not aware of any readily available parameters that would provide such an identifier.

Correct, the invocation of system.perspective.openPopup() needs to supply a unique id arg/kwarg value, AND it needs to pass that exact same value as part of the params of the Popup.

unique_id = "SomeUniqueValue"  # use this as the Popup's id AND pass it as a param
system.perspective.openPopup(id=unique_id, view=... params={"popup_id":unique_id})  # complete with relevant kwargs

Is there an existing parameter in a view that could be used as this unique identifier? I am trying to avoid a situation in which view (A) would be embedded in a large number of views (think views (D-Z)) and each view would need to be given a custom parameter that would need to be maintained as unique.

Use a custom parameter in each view that is bound to an expression that produces a one-time UUID or other unique randomish string.

Thank you for the help. I was able to get it to work by using system.date.now() as the generator of a non-repeating number, and calling the popup from a script.