From 6535233f952be866d624ad1a573562c6706138de Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 2 Jul 2006 03:17:18 +0000 Subject: Fixed #262. --- framework/Web/UI/WebControls/TCheckBox.php | 46 +++++++++++++++++++-------- framework/Web/UI/WebControls/TRadioButton.php | 3 ++ 2 files changed, 35 insertions(+), 14 deletions(-) (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php index 3eb486f3..1dc177cf 100644 --- a/framework/Web/UI/WebControls/TCheckBox.php +++ b/framework/Web/UI/WebControls/TCheckBox.php @@ -60,13 +60,10 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl public function loadPostData($key,$values) { $checked=$this->getChecked(); - if(isset($values[$key])!=$checked) - { - $this->setChecked(!$checked); - return true; - } - else - return false; + if($newChecked=isset($values[$key])) + $this->setValue($values[$key]); + $this->setChecked($newChecked); + return $newChecked!==$checked; } /** @@ -133,6 +130,22 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl $this->setViewState('Text',$value,''); } + /** + * @return string the value of the checkbox. Defaults to empty. + */ + public function getValue() + { + return $this->getViewState('Value',''); + } + + /** + * @param string the value of the checkbox + */ + public function setValue($value) + { + $this->setViewState('Value',$value,''); + } + /** * @return string the alignment (Left or Right) of the text caption, defaults to Right. */ @@ -309,13 +322,18 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl */ protected function getValueAttribute() { - $attributes=$this->getViewState('InputAttributes',null); - if($attributes && $attributes->contains('value')) - return $attributes->itemAt('value'); - else if($this->hasAttribute('value')) - return $this->getAttribute('value'); + if(($value=$this->getValue())!=='') + return $value; else - return ''; + { + $attributes=$this->getViewState('InputAttributes',null); + if($attributes && $attributes->contains('value')) + return $attributes->itemAt('value'); + else if($this->hasAttribute('value')) + return $this->getAttribute('value'); + else + return ''; + } } /** @@ -345,7 +363,7 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl if($clientID!=='') $writer->addAttribute('id',$clientID); $writer->addAttribute('type','checkbox'); - if(($value = $this->getValueAttribute()) !== '') + if(($value=$this->getValueAttribute())!=='') $writer->addAttribute('value',$value); if($onclick!=='') $writer->addAttribute('onclick',$onclick); diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php index 2ccda96b..9198be1b 100644 --- a/framework/Web/UI/WebControls/TRadioButton.php +++ b/framework/Web/UI/WebControls/TRadioButton.php @@ -101,6 +101,9 @@ class TRadioButton extends TCheckBox $this->setViewState('GroupName',$value,''); } + /** + * @return string the value attribute to be rendered + */ protected function getValueAttribute() { if(($value=parent::getValueAttribute())==='') -- cgit v1.2.3