Browse Source

closes #272 - radio group behavior broken when in optional section

issue-272-optional-radio-group-behavior
chriskiehl 6 years ago
parent
commit
d5bf4972d6
1 changed files with 17 additions and 8 deletions
  1. 25
      gooey/gui/components/widgets/radio_group.py

25
gooey/gui/components/widgets/radio_group.py

@ -71,18 +71,27 @@ class RadioGroup(BaseWidget):
def handleButtonClick(self, event):
if not self.widgetInfo['required']:
# if it's not a required group, allow deselection of the
# current option if the user clicks on a selected radio button
if event.EventObject.Id == getattr(self.selected, 'Id', None)\
and event.EventObject.GetValue():
event.EventObject.SetValue(False)
else:
self.selected = event.EventObject
currentSelection = self.selected
nextSelection = event.EventObject
if not self.isSameRadioButton(currentSelection, nextSelection):
self.selected = nextSelection
self.selected.SetValue(True)
else:
# user clicked on an already enabled radio button.
# if it is not in the required section, allow it to be deselected
if not self.widgetInfo['required']:
self.selected.SetValue(False)
self.applyStyleRules()
self.handleImplicitCheck()
def isSameRadioButton(self, radioButton1, radioButton2):
return (getattr(radioButton1, 'Id', 'r1-not-found') ==
getattr(radioButton2, 'Id', 'r2-not-found'))
def applyStyleRules(self):
"""
Conditionally disabled/enables form fields based on the current

Loading…
Cancel
Save