From 4cf72b151eba3357da19d670c8cccd49851a5fbe Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 2 Sep 2006 12:00:12 +0000 Subject: Fixed #356. --- framework/Web/UI/WebControls/TLabel.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'framework') diff --git a/framework/Web/UI/WebControls/TLabel.php b/framework/Web/UI/WebControls/TLabel.php index a7a25eef..65517fc9 100644 --- a/framework/Web/UI/WebControls/TLabel.php +++ b/framework/Web/UI/WebControls/TLabel.php @@ -20,6 +20,7 @@ * To use TLabel as a form label, associate it with a control by setting the * {@link setForControl ForControl} property. * The associated control must be locatable within the label's naming container. + * If the associated control is not visible, the label will not be rendered, either. * * Note, {@link setText Text} will NOT be encoded for rendering. * Make sure it does not contain dangerous characters that you want to avoid. @@ -31,6 +32,8 @@ */ class TLabel extends TWebControl { + private $_forControl=''; + /** * @return string tag name of the label, returns 'label' if there is an associated control, 'span' otherwise. */ @@ -45,15 +48,35 @@ class TLabel extends TWebControl * @throws TInvalidDataValueException if associated control cannot be found using the ID */ protected function addAttributesToRender($writer) + { + if($this->_forControl!=='') + $writer->addAttribute('for',$this->_forControl); + parent::addAttributesToRender($writer); + } + + /** + * Renders the label. + * It overrides the parent implementation by checking if an associated + * control is visible or not. If not, the label will not be rendered. + * @param THtmlWriter writer + */ + public function render($writer) { if(($aid=$this->getForControl())!=='') { if($control=$this->findControl($aid)) - $writer->addAttribute('for',$control->getClientID()); + { + if($control->getVisible(true)) + { + $this->_forControl=$control->getClientID(); + parent::render($writer); + } + } else throw new TInvalidDataValueException('label_associatedcontrol_invalid',$aid); } - parent::addAttributesToRender($writer); + else + parent::render($writer); } /** -- cgit v1.2.3