Hello, can someone please advise me how to make a toggle button with confirmation.
This means that after clicking, the bound value is not set immediately, but only after confirmation from the message box. And the same when turning it off.
The button must also change state (pressed/unpressed) according to the state of the variable that is bound.
Thanks in advance for help.
Hello Frantisek,
One option (I don’t know if this is the best solution) would be to place a button (bt1) above the toggle button (tb1). bt1 should be made invisible via styling.
bt1 would then open a dialog or message box via an event. After the query, tb1 is then set.
The variable is directly bound to tb1. However, this cannot be set directly because the invisible bt1 is above it.
Hopefully this helps you.
Best regards,
Simon
I would just use one ToggleButton and show MessageBox or Dialog with the valueChanged event.
The CheckBox is bound to the ::Program:visibleAltTDCPosition variable, the ToggleButton isn’t bound to anything just used for the valueChange event.
The newValueBool condition is not really necessary just in case you want to show a different MsgBox for setting / resetting.
EDIT / MODIFICATION:
I realized a flaw in my original suggestion so here is a modified suggestion that also works if you change your mind and select to not confirm the change.
So now just using the click event but reading the variable state and based on that the MsgBox result now either sets / resets variable but also the ToggleButton state.
Thanks for the ideas.
To Simon Stoll:
Overlaying the toggle button with another element is functional. I already used this in VC4 (hotspot), in mappView I used a transparent image and the click event. It works both when clicking and when changing a variable from the PLC.
To Marcel Voigt:
Thank you for the useful ideas. But unfortunately this solution does not reflect the change of the variable in an event other than clicking on a specific button. The given variable can be changed by the program for example…
To both:
Thank you for your time and idea
I wasn’t sure if a change of the variable from code was also required and therefore I didn’t add that in but it’s quite simple to cover that use case.
If the variable changes value you can set the ToggleButton accordingly, that also covers the initial state of the ToogleButton when the content is first loaded.