From d5bf4972d61298742c75c835f1a9e9fa710fa4f3 Mon Sep 17 00:00:00 2001 From: chriskiehl Date: Sun, 4 Mar 2018 13:12:19 -0800 Subject: [PATCH] closes #272 - radio group behavior broken when in optional section --- gooey/gui/components/widgets/radio_group.py | 25 ++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gooey/gui/components/widgets/radio_group.py b/gooey/gui/components/widgets/radio_group.py index c9b5296..eaf8dad 100644 --- a/gooey/gui/components/widgets/radio_group.py +++ b/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