summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/UI/WebControls/TBaseValidator.php40
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