Add confirmation message with Toggle Switch

There is a problem with your approach. The Toggle Switch will turn on before the onActionPerformed event occurs.

If you want to do this, I suggest:

  • Create a Confirm / Cancel dialog view that can be used anywhere in your program.
  • Give it parameters. For example,
    • Title (for optional titlebar on popup).
    • User prompt. e.g. "Confirm switch on MANUAL mode?"
    • Message handler name. You are going to need to to add a message handler to the MANUAL toggle switch to respond to the sendMessage passed back from the popup.
  • On the Confirm button, right-click, Configure Events.
Script
def runAction(self, event):
	msg = self.view.params.messageName
	system.perspective.sendMessage(msg, {'confirm': True}, scope = 'page')
  • Do the same on the Cancel button but set {'confirm': False}.
    That should be all you need to do on the popup.

On the toggle switch:

  • Add a custom property confirmedSelected. Set it to false for now. This is the value your application will actually use - not the props.selected value which will change state before you have confirmed it.
  • On the toggle switch, right-click, Configure Scripts.
Script
def onMessageReceived(self, payload):
	if payload['confirm']:
		self.custom.confirmedSelected = True
	else:
		self.custom.confirmedSelected = False
		self.props.selected = False

Remember, the MANUAL mode tag will be contolled by a binding to custom.confirmedSelected (and not props.selected).

Add the tag from the dropdown. (Don't type it out in the title. I fixed it.)

1 Like