From 8d8b6688cbbb1febe92012ccc2a4158fa594fcb3 Mon Sep 17 00:00:00 2001 From: wei <> Date: Wed, 5 Jul 2006 04:23:43 +0000 Subject: Fixed #223 #225 --- framework/Web/UI/WebControls/TRadioButton.php | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'framework/Web/UI/WebControls/TRadioButton.php') diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php index 9198be1b..6ddd7c96 100644 --- a/framework/Web/UI/WebControls/TRadioButton.php +++ b/framework/Web/UI/WebControls/TRadioButton.php @@ -37,6 +37,8 @@ Prado::using('System.Web.UI.WebControls.TRadioButtonList'); * between posts to the server. * * TRadioButton uses {@link setGroupName GroupName} to group together a set of radio buttons. + * Once the {@link setGroupName GroupName} is set, you can use the {@link getRadioButtonsInGroup} + * method to get an array of TRadioButtons having the same group name. * * If {@link setAutoPostBack AutoPostBack} is set true, changing the radio button state * will cause postback action. And if {@link setCausesValidation CausesValidation} @@ -53,6 +55,10 @@ Prado::using('System.Web.UI.WebControls.TRadioButtonList'); */ class TRadioButton extends TCheckBox { + /** + * @param array list of radio buttons registered. + */ + private static $_radiobuttons=array(); /** * @var string the name used to fetch radiobutton post data */ @@ -99,6 +105,36 @@ class TRadioButton extends TCheckBox public function setGroupName($value) { $this->setViewState('GroupName',$value,''); + $this->registerRadioButton($this); + } + + /** + * Register radio button control grouping. + * @param TRadioButton control to add + */ + private function registerRadioButton(TRadioButton $control) + { + $id = $control->getUniqueID(); + if(!isset(self::$_radiobuttons[$id])) + self::$_radiobuttons[$id] = $control; + } + + /** + * Gets an array of RadioButtons with same group name. + * Radio buttons are grouped when the GroupName property is set. + * This method will always return at least the current radio button in the array. + * @return array list of TRadioButton with the same group + */ + public function getRadioButtonsInGroup() + { + $group = $this->getUniqueGroupName(); + $buttons = array(); + foreach(self::$_radiobuttons as $control) + { + if($control->getUniqueGroupName() === $group) + $buttons[] = $control; + } + return count($buttons) > 0 ? $buttons : array($this); } /** -- cgit v1.2.3