From 4cf72b151eba3357da19d670c8cccd49851a5fbe Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 2 Sep 2006 12:00:12 +0000 Subject: Fixed #356. --- HISTORY | 1 + framework/Web/UI/WebControls/TLabel.php | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index e200ad70..7652c49a 100644 --- a/HISTORY +++ b/HISTORY @@ -11,6 +11,7 @@ ENH: Uses uncompressed javascript in debug mode. (Wei) ENH: Cells in TDataGrid rows can now be accessed via the corresponding column IDs (Qiang) ENH: Input controls in some datagrid columns can now be accessed in a named fashion (Qiang) ENH: Prado::fatalError() now displays function parameter information (Qiang) +CHG: Ticket#356 - TLabel will not render if its associated control is invisible (Qiang) CHG: Validator the error message visibility before raising events OnError and OnSuccess (Wei) CHG: Unify all client-side javascript event handler syntax. (Wei) CHG: Added more conditions in the requirement checker (Qiang) 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