From 2ff1a4bcb650b0dce241c2d947fbf59759c2efff Mon Sep 17 00:00:00 2001 From: mikl <> Date: Thu, 17 Apr 2008 16:16:03 +0000 Subject: Fixed #622 --- framework/Web/UI/WebControls/TCheckBox.php | 39 +++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'framework/Web/UI/WebControls/TCheckBox.php') diff --git a/framework/Web/UI/WebControls/TCheckBox.php b/framework/Web/UI/WebControls/TCheckBox.php index 7a0fc603..4061f217 100644 --- a/framework/Web/UI/WebControls/TCheckBox.php +++ b/framework/Web/UI/WebControls/TCheckBox.php @@ -40,7 +40,7 @@ * @package System.Web.UI.WebControls * @since 3.0 */ -class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatable, IDataRenderer +class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatable, IDataRenderer, IControlContainer { private $_dataChanged=false; @@ -267,6 +267,14 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl $this->setViewState('ValidationGroup',$value,''); } + /** + * @return string the id of the surrounding tag or this clientID if no such tag present + */ + public function getContainerClientID() + { + return $this->getSpanNeeded() ? $this->getClientID().'_parent' : $this->getClientID(); + } + /** * Renders the checkbox control. * This method overrides the parent implementation by rendering a checkbox input element @@ -276,17 +284,10 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl public function render($writer) { $this->getPage()->ensureRenderInForm($this); - $needSpan=false; if($this->getHasStyle()) - { $this->getStyle()->addAttributesToRender($writer); - $needSpan=true; - } if(($tooltip=$this->getToolTip())!=='') - { $writer->addAttribute('title',$tooltip); - $needSpan=true; - } if($this->getHasAttributes()) { $attributes=$this->getAttributes(); @@ -295,17 +296,17 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl if(($onclick=$attributes->remove('onclick'))===null) $onclick=''; if($attributes->getCount()) - { $writer->addAttributes($attributes); - $needSpan=true; - } if($value!==null) $attributes->add('value',$value); } else $onclick=''; - if($needSpan) + if($needspan=$this->getSpanNeeded()) + { + $writer->addAttribute('id',$this->getContainerClientID()); $writer->renderBeginTag('span'); + } $clientID=$this->getClientID(); if(($text=$this->getText())!=='') { @@ -322,7 +323,7 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl } else $this->renderInputTag($writer,$clientID,$onclick); - if($needSpan) + if($needspan) $writer->renderEndTag(); } @@ -391,6 +392,16 @@ class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatabl $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true); } + /** + * Check if we need a span tag to surround this control. The span tag will be created if + * the Text property is set for this control. + * + * @return bool wether this control needs a surrounding span tag + */ + protected function getSpanNeeded() { + return $this->getText()!==''; + } + /** * Renders a label beside the checkbox. * @param THtmlWriter the writer for the rendering purpose @@ -500,4 +511,4 @@ class TTextAlign extends TEnumerable const Right='Right'; } -?> \ No newline at end of file +?> -- cgit v1.2.3