Deselecting radio button

Hello All,

I have a screen with 3 radio button options on it-
NG TEST 1
NG TEST 2
NG TEST 4
When these are selected, they send different values to a tag.

NG TEST 1 = 2 for Bordesholm_EFR Testing.
NG TEST 1 = 4 for Bordesholm_EFR Testing.
NG TEST 1 = 0 for Bordesholm_EFR Testing.

I need to use a confirmation dialogue box with “Are you sure” message when anyone selects any of the radio buttons.

I am using a script on ‘mouse clicked’ to generate the confirmation dialogue and writing to the tag if a yes is selected.

if system.gui.confirm(u’Are you sure?’, ‘Confirm’):
SiteName = system.tag.read("[Client]SiteName").value
system.tag.writeToTag(‘SystemTags/Simulation/’ + SiteName + ‘_EFR_Testing’, 2)
else:
event.source.selected = 0

If the user selects ‘No’ on the confirmation dialogue, It does not write the value to the tag. (which is what I want).

My question is - Along with not changing the tag value, is it possible to deselect the radio button as well? Is there any way?

Aware that the manual says - “One radio button is selected at a time under any container”

Thanks

One of the radio boxes will always be selected, that is how they work.
If you want to be able to have none selected you will have to use Check Boxes and maintain state for all 3 when one is selected.

Add a hidden radio button and default back to it.

if system.gui.confirm(u'Are you sure?', 'Confirm'):
  SiteName = system.tag.read("[Client]SiteName").value
  system.tag.writeToTag(‘SystemTags/Simulation/’ + SiteName + '_EFR_Testing', 2)
else:
  event.source.parent.getComponent('Default Radio Button').selected = 0
3 Likes
rb1 = event.source.parent.getComponent('Radio Button1')

buttonGroup = rb1.getModel().getGroup()
buttonGroup.clearSelection()
1 Like

Hi Jordan,

The hidden radio button Idea works perfectly fine. Thanks.

Hello jpark,

I also wanted to try this idea without using hidden button, But couldnt get the script working.
My script looked like -

if system.gui.confirm(u’Are you sure?’, ‘Confirm’):
SiteName = system.tag.read("[Client]SiteName").value
system.tag.writeToTag(‘SystemTags/Simulation/’ + SiteName + ‘_EFR_Testing’, 2)

else:

rb1 = event.source.selected
buttonGroup = rb1.getModel().getGroup()
buttonGroup.clearSelection()

But when I select a ‘No’ confirmation it comes up with an error -

Traceback (most recent call last):

File “event:mouseClicked”, line 8, in

AttributeError: ‘bool’ object has no attribute ‘getModel’

Ignition v7.8.5 (b2016120813)
Java: Oracle Corporation 1.8.0_161

Compare your rb1=... assignment to @jpark’s rb1=... assignment.

Hello @pturmel,
I had tried it that way. But it doesn’t accept the assignment. It requests for a bound property. I many be wrong in my assumption, but i assumed that we might need to use the .selected property for this assignment.

The .getModel() method applies to the radio button component itself, not to any of its properties.

Are you referring to when you use the property browser it won’t let you select just the component, but requires you to select a property in that component? If so, just type the component path in, or select a property then delete the .value or .data or whatever property you chose.

It works now on the suggestion by @jpark earlier.

@pturnel: Thanks,yes it works on the component itself. I had to get rid of the .selected option to get it working (Thanks @dkhayes117)

Thanks All.

Regards