From 610a6c68b9d3a3d4cacf71e0d6f4ab7cce3b969c Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 22 Jul 2006 16:53:55 +0000 Subject: fixed #178. --- framework/Web/UI/WebControls/TRadioButton.php | 45 +++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'framework') diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php index 7096647b..74e908ca 100644 --- a/framework/Web/UI/WebControls/TRadioButton.php +++ b/framework/Web/UI/WebControls/TRadioButton.php @@ -67,6 +67,10 @@ class TRadioButton extends TCheckBox * @var integer global ID of this radiobutton */ private $_globalID; + /** + * @var string previous UniqueID (used to calculate UniqueGroup) + */ + private $_previousUniqueID=null; /** * @var string the name used to fetch radiobutton post data */ @@ -140,12 +144,45 @@ class TRadioButton extends TCheckBox } /** - * Sets the name of the group that the radio button belongs to + * Sets the name of the group that the radio button belongs to. + * The group is unique among the control's naming container. * @param string the group name + * @see setGlobalGroupName */ public function setGroupName($value) { $this->setViewState('GroupName',$value,''); + $this->_uniqueGroupName=null; + } + + /** + * @return string the name of the global group that the radio button belongs to. Defaults to empty. + */ + public function getGlobalGroupName() + { + return $this->getViewState('GlobalGroupName',''); + } + + /** + * Sets the name of the global group that the radio button belongs to. + * A global group is a radiobutton group unique in the whole page hierarchy, + * while the {@link setGroupName GroupName} specifies a group that is unique + * among the control's naming container. + * For example, each cell of a {@link TDataGrid} is a naming container. + * If you specify {@link setGroupName GroupName} for a radiobutton in a cell, + * it groups together radiobutton within a cell, but not the other, even though + * they have the same {@link setGroupName GroupName}. + * On the contratry, if {@link setGlobalGroupName GlobalGroupName} is used instead, + * it will group all appropriate radio buttons on the whole page hierarchy. + * Note, when both {@link setGlobalGroupName GlobalGroupName} and + * {@link setGroupName GroupName}, the former takes precedence. + * @param string the group name + * @see setGroupName + */ + public function setGlobalGroupName($value) + { + $this->setViewState('GlobalGroupName',$value,''); + $this->_uniqueGroupName=null; } /** @@ -182,10 +219,12 @@ class TRadioButton extends TCheckBox */ private function getUniqueGroupName() { - if($this->_uniqueGroupName===null) + if(($groupName=$this->getGlobalGroupName())!=='') + return $groupName; + else if(($uniqueID=$this->getUniqueID())!==$this->_previousUniqueID || $this->_uniqueGroupName===null) { $groupName=$this->getGroupName(); - $uniqueID=$this->getUniqueID(); + $this->_previousUniqueID=$uniqueID; if($uniqueID!=='') { if(($pos=strrpos($uniqueID,TControl::ID_SEPARATOR))!==false) -- cgit v1.2.3