diff options
| author | xue <> | 2006-02-07 02:58:37 +0000 | 
|---|---|---|
| committer | xue <> | 2006-02-07 02:58:37 +0000 | 
| commit | 956117a3a2bdbdfb996d15746be058467bb783ff (patch) | |
| tree | b5cd0eadce2c4fd7041ff44946c28db58bfe5b5f | |
| parent | 9d904fdfba3fd2925d7c121f2ec0d68a5ac18ab9 (diff) | |
Added ControlCssClass property to TBaseValidator.
| -rw-r--r-- | framework/Web/UI/WebControls/TBaseValidator.php | 40 | 
1 files changed, 39 insertions, 1 deletions
diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index 7520933a..8e8566c9 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -138,6 +138,7 @@ abstract class TBaseValidator extends TLabel implements IValidator  		$options['focuselementid'] = $this->getFocusElementID();  		$options['validationgroup'] = $this->getValidationGroup();  		$options['controltovalidate'] = $this->getValidationTarget()->getClientID(); +		$options['controlcssclass'] = $this->getControlCssClass();  		return $options;  	} @@ -149,6 +150,7 @@ abstract class TBaseValidator extends TLabel implements IValidator  	 */  	public function onPreRender($param)  	{ +		parent::onPreRender($param);  		$scripts = $this->getPage()->getClientScript();  		$formID=$this->getPage()->getForm()->getClientID();  		$scriptKey = "TBaseValidator:$formID"; @@ -159,7 +161,27 @@ abstract class TBaseValidator extends TLabel implements IValidator  		}  		if($this->getEnableClientScript())  			$this->registerClientScriptValidator(); -		parent::onPreRender($param); +		$this->updateControlCssClass(); +	} + +	/** +	 * Update the ControlToValidate component's css class depending +	 * if the ControlCssClass property is set, and whether this is valid. +	 * @return boolean true if change, false otherwise. +	 */ +	protected function updateControlCssClass() +	{ +		if(($cssClass=$this->getControlCssClass())!=='') +		{ +			$control=$this->getValidationTarget(); +			if($control instanceof TWebControl) +			{ +				$class = preg_replace ('/ '.preg_quote($cssClass).'/', '',$control->getCssClass()); +				if(!$this->isValid()) +					$class .= ' '.$cssClass; +				$control->setCssClass($class); +			} +		}  	}  	/** @@ -381,6 +403,22 @@ abstract class TBaseValidator extends TLabel implements IValidator  	}  	/** +	 * @return string the css class that is applied to the control being validated in case the validation fails +	 */ +	public function getControlCssClass() +	{ +		return $this->getViewState('ControlCssClass',''); +	} + +	/** +	 * @param string the css class that is applied to the control being validated in case the validation fails +	 */ +	public function setControlCssClass($value) +	{ +		$this->setViewState('ControlCssClass',$value,''); +	} + +	/**  	 * This is the major method for validation.  	 * Derived classes should implement this method to provide customized validation.  	 * @return boolean whether the validation succeeds  | 
