Perspective - Popup - OnClose than Focus on Input

Hello,
i would like to ask for help with my Perspective application.
I have popup for confirmation of user action. After popup close I need to re-focus the input on parent view (see screen).

Is that somehow possible?

Thank you

Screenshot 2021-04-13 084204

Kinda same question here. I could open the popup from any page and any field. When the popup is closed, I want focus to be back on same page, same field.

I have sent self asa parameter to the popup:

	system.perspective.openPopup("errorPopup","Pages/errorPopup",
		params={"errorMessage":self.props.text,"backFocus":self}, 
		title = "Error", modal = True, showCloseIcon  = False)

then when I close the popup, I do this:

      system.perspective.closePopup(errorPopup)
      self.view.params.backFocus.props.placeholder = I'm Back!

When I send self to the popup, it is type self was typed as

<type com.inductiveautomation.perspective.gateway.script.ComponentModelScriptWrapper$SafetyWrapper'>

But once in the popup, it is type unicode or <PropertyTreeScriptWrapper>: {u'text': u'wow', u'placeholder': u'', u'enabled': True, u'deferUpdates': True, u'rejectUpdatesWhileFocused': True, u'style': {u'classes': u''}} so I can’t use it to return whence it came.

TIA
Ken

The biggest hurdle is going to be this:

There's no way in perspective to dynamically specify components across Views/Pages at the session level, which is what this sort of implies.

So the best you could do would be the following:

  • Any component which would open the popup would need to pass along its own UNIQUE name as a parameter of the Popup.
	system.perspective.openPopup("errorPopup","Pages/errorPopup",
		params={"errorMessage":self.props.text,"backFocus":self, "originatingComponent": self.meta.name}, 
		title = "Error", modal = True, showCloseIcon  = False)
  • The popup would need to broadcast a message BEFORE the Popup is closed.
# The scope is very important in the next line
system.perspective.sendMessage("POPUPCLOSED", payload={"originatingComponent": self.view.params.originatingComponent}, scope="page")
# This next line assumes that the errorPopup variable is actually a reference to the ID of the popup we are targeting.
system.perspective.closePopup(errorPopup)
  • Every component which could open this popup would need a configured Message Handler Listener (right-click component -> Configure Scripts) with a name of "POPUPCLOSED", a scope of "page" (session will not get you what you want), and the following code:
if payload['originatingComponent'] == self.meta.name:
    self.focus()

Also, note that this will ONLY work if the user clicks the provided Button which closes the Popup; if the user elects to close the Popup through the closeIcon present in the title bar of the Popup, the code will not execute and the focus will not be re-allocated to the component which originated the Popup.

2 Likes

Thanks, that is pretty much what I had come up with but hadn’t gotten it all implemented yet, I was hoping to get away without a message handler on every page, but this confirms I need it. It’s good to have the deeper detail that you are providing vis a vis scope. Thanks so much for the help

Ken

1 Like

I’m using a modal popup. So the requirement to go back to any page is somewhat constrained. It will go back only to the page that initiated the popup. However, there are a number of pages where that could happen. Therefore, I don’t think the originatingComponent has to be unique across pages. I tested it with non-unique names and it didn’t get confused.

And I had already gotten rid of the X, the person has to scan or type in ACK to acknowledge that they saw the popup before it is allowed to close.

Thanks again!

Correct. Since we've limited the scope of the "broadcast" to that of the page, the name only needs to be unique among components on that page.