Dropdown confirmation not working?

Will someone double-check me on this: When a dropdown component has the comfirmation enabled, and during runtime the user selects NO in the confirmation box, the event will not change the tag or property it would have changed if the user had chosen YES...., but it does change the selectedValue and selectedString. So, the user selects NO, and correctly the event doesn't trigger, but the list still shows the selected string and the selectedValue also changes, even though the user selected NO.

The dropdown component doesn’t have built-in confirmation. Are you doing confirmation in an event handler (script)? Are you using a different component?

We are doing it in the Event handler, on a Property change. (We specify a change in the selectedValue).

In that case the value will update regardless of whether or not the user selects yes or no. If you change the value back it will run the propertyChange script again.

Yes, we tried that too, with that exact result. How can we get it to not change if the operator selects NO on the confirmation?

What you can do is throw in a boolean variable to handle the case where the user selects “NO”, which will fire another propertyChange event since the selectedValue/selectedLabel/etc will be changed back to its original value. Try creating a script module under the app package called “test” and add this script to the module. Then you can reference it from the event handler of the dropdown with app.test.confirm(event).

[code]global flag
flag = 0

def confirm(event):
import system
global flag
if event.propertyName == “selectedLabel” and not flag:
if not system.gui.confirm(“Are you sure?”):
event.source.selectedLabel = event.oldValue
flag = 1

elif event.propertyName == "selectedLabel" and flag:
	flag = 0

[/code]

James, Thank you for the help and code. We implemented your suggestion, and it worked fantastically! Thanks again :smiley:

What I found to do with a dropdown is as follows:

  • make a custom property integer 'valueConfirmed'
    Connect your tag bidirectional with that property.
  • Connect your tag not bidirectional with the 'selected value'

And then in propertyChange of the dropdown following code:

if event.propertyName == "selectedValue" and event.source.valueConfirmed != event.newValue:
	title = "Change dropdown value."
	message = "Are u sure you want to change te value to " + event.source.selectedStringValue
	
	if system.gui.confirm(message,title):
		event.source.valueConfirmed = event.newValue
	else:
		event.source.selectedValue = event.oldValue

And so everything can be in the same component.

1 Like

I recommend never using the system.gui.* popups. They are poison for event handling in your UI.

Use the technique you describe to enable a separate "Save" button to handle the situation correctly. I use an additional "Dirty" custom property to style fields that have changes. Some discussions of this:

https://forum.inductiveautomation.com/search?q=%40pturmel%20raw%20dirty