From 2da825c6f1dd3726bcc866082f6d28dcc29a0c5a Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 10 Jun 2006 12:39:49 +0000 Subject: Fixed #182. --- framework/Web/UI/WebControls/TBaseValidator.php | 79 ++++++++++++---------- framework/Web/UI/WebControls/TBulletedList.php | 10 +++ framework/Web/UI/WebControls/TCheckBoxList.php | 10 +++ framework/Web/UI/WebControls/TCompareValidator.php | 14 +++- framework/Web/UI/WebControls/TCustomValidator.php | 10 +++ .../Web/UI/WebControls/TDataTypeValidator.php | 10 +++ framework/Web/UI/WebControls/TDropDownList.php | 10 +++ .../Web/UI/WebControls/TEmailAddressValidator.php | 10 +++ framework/Web/UI/WebControls/TListBox.php | 10 +++ framework/Web/UI/WebControls/TListControl.php | 9 ++- .../Web/UI/WebControls/TListControlValidator.php | 12 +++- framework/Web/UI/WebControls/TRadioButtonList.php | 10 +++ framework/Web/UI/WebControls/TRangeValidator.php | 10 +++ .../UI/WebControls/TRegularExpressionValidator.php | 10 +++ .../Web/UI/WebControls/TRequiredFieldValidator.php | 16 ++++- 15 files changed, 186 insertions(+), 44 deletions(-) (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index 9ff2a97d..54fea2ec 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -158,18 +158,18 @@ abstract class TBaseValidator extends TLabel implements IValidator $options['ValidationGroup'] = $this->getValidationGroup(); $options['ControlToValidate'] = $control->getClientID(); $options['ControlCssClass'] = $this->getControlCssClass(); - + $options['ControlType'] = $this->getClientControlClass($control); - + if(!is_null($this->_clientScript)) $options = array_merge($options,$this->_clientScript->getOptions()); - + return $options; } - + /** * Gets the Control type for client-side validation. If new cases exists in - * TBaseValidator::$_clientClass, be sure to update the corresponding + * TBaseValidator::$_clientClass, be sure to update the corresponding * "Javascript/validation3.js" file as well. * @param TControl control to validate. * @return string control type for client-side validation. @@ -181,21 +181,21 @@ abstract class TBaseValidator extends TLabel implements IValidator return $type; return get_class($control); } - + /** * Gets the TValidatorClientScript that allows modification of the client- - * side validator events. - * + * side validator events. + * * The client-side validator supports the following events. * # OnValidate -- raised before client-side validation is - * executed. + * executed. * # OnSuccess -- raised after client-side validation is completed * and is successfull, overrides default validator error messages updates. * # OnError -- raised after client-side validation is completed - * and failed, overrides default validator error message updates. - * + * and failed, overrides default validator error message updates. + * * You can attach custom javascript code to each of these events - * + * * @return TValidatorClientScript javascript validator event options. */ public function getClientSide() @@ -204,7 +204,7 @@ abstract class TBaseValidator extends TLabel implements IValidator $this->_clientScript = $this->createClientScript(); return $this->_clientScript; } - + /** * @return TValidatorClientScript javascript validator event options. */ @@ -228,7 +228,7 @@ abstract class TBaseValidator extends TLabel implements IValidator if($this->getEnableClientScript() && !$scripts->isEndScriptRegistered($scriptKey)) { $manager['FormID'] = $formID; - $options = TJavaScript::encode($manager); + $options = TJavaScript::encode($manager); $scripts->registerPradoScript('validator'); $scripts->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});"); } @@ -264,15 +264,20 @@ abstract class TBaseValidator extends TLabel implements IValidator { if($this->getEnabled(true)) { - $class = get_class($this); - $scriptKey = "prado:".$this->getClientID(); - $scripts = $this->getPage()->getClientScript(); - $options = TJavaScript::encode($this->getClientScriptOptions()); - $js = "new Prado.WebUI.{$class}({$options});"; - $scripts->registerEndScript($scriptKey, $js); + $key = 'prado:'.$this->getClientID(); + $options = TJavaScript::encode($this->getClientScriptOptions()); + $script = 'new '.$this->getClientClassName().'('.$options.');'; + $this->getPage()->getClientScript()->registerEndScript($key, $script); } } + /** + * Gets the name of the javascript class responsible for performing validation for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + abstract protected function getClientClassName(); + /** * This method overrides the parent implementation to forbid setting ForControl. * @param string the associated control ID @@ -515,22 +520,22 @@ abstract class TBaseValidator extends TLabel implements IValidator /** * TValidatorClientScript class. - * + * * Client-side validator events can be modified through the {@link * TBaseValidator::getClientSide ClientSide} property of a validator. The * subproperties of ClientSide are those of the TValidatorClientScript * properties. The client-side validator supports the following events. - * + * * The OnValidate event is raise before the validator validation * functions are called. - * + * * The OnSuccess event is raised after the validator has successfully * validate the control. - * + * * The OnError event is raised after the validator fails validation. - * + * * See the quickstart documentation for further details. - * + * * @author Wei Zhuo * @version $Revision: $ $Date: $ * @package System.Web.UI.WebControls @@ -542,7 +547,7 @@ class TValidatorClientScript extends TComponent * @var TMap client-side validator event javascript code. */ private $_options; - + /** * Constructor. */ @@ -550,25 +555,25 @@ class TValidatorClientScript extends TComponent { $this->_options = new TMap; } - + /** * @return string javascript code for client-side OnValidate event. */ public function getOnValidate() { - return $this->_options->itemAt['OnValidate']; + return $this->_options->itemAt['OnValidate']; } - + /** * Client-side OnValidate validator event is raise before the validators - * validation functions are called. + * validation functions are called. * @param string javascript code for client-side OnValidate event. */ public function setOnValidate($javascript) { $this->_options->add('OnValidate', $this->ensureFunction($javascript)); } - + /** * Client-side OnSuccess event is raise after validation is successfull. * This will override the default client-side validator behaviour. @@ -578,7 +583,7 @@ class TValidatorClientScript extends TComponent { $this->_options->add('OnSuccess', $this->ensureFunction($javascript)); } - + /** * @return string javascript code for client-side OnSuccess event. */ @@ -586,7 +591,7 @@ class TValidatorClientScript extends TComponent { return $this->_options->itemAt('OnSuccess'); } - + /** * Client-side OnError event is raised after validation failure. * This will override the default client-side validator behaviour. @@ -596,7 +601,7 @@ class TValidatorClientScript extends TComponent { $this->_options->add('OnError', $this->ensureFunction($javascript)); } - + /** * @return string javascript code for client-side OnError event. */ @@ -604,7 +609,7 @@ class TValidatorClientScript extends TComponent { return $this->_options->itemAt('OnError'); } - + /** * @return array list of client-side event code. */ @@ -612,7 +617,7 @@ class TValidatorClientScript extends TComponent { return $this->_options->toArray(); } - + /** * Ensure the string is a valid javascript function. If the string begins * with "javascript:" valid javascript function is assumed, otherwise the diff --git a/framework/Web/UI/WebControls/TBulletedList.php b/framework/Web/UI/WebControls/TBulletedList.php index 05cbaab1..4274154e 100644 --- a/framework/Web/UI/WebControls/TBulletedList.php +++ b/framework/Web/UI/WebControls/TBulletedList.php @@ -83,6 +83,16 @@ class TBulletedList extends TListControl implements IPostBackEventHandler return 'ul'; } + /** + * Gets the name of the javascript class responsible for performing postback for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TBulletedList'; + } + /** * Adds attribute name-value pairs to renderer. * This overrides the parent implementation with additional bulleted list specific attributes. diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php index 2a16673c..e6ca3642 100644 --- a/framework/Web/UI/WebControls/TCheckBoxList.php +++ b/framework/Web/UI/WebControls/TCheckBoxList.php @@ -105,6 +105,16 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont return new TTableStyle; } + /** + * Gets the name of the javascript class responsible for performing postback for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TCheckBoxList'; + } + /** * @return string the alignment of the text caption, defaults to 'Right'. */ diff --git a/framework/Web/UI/WebControls/TCompareValidator.php b/framework/Web/UI/WebControls/TCompareValidator.php index b5ebd3ab..93664b2e 100644 --- a/framework/Web/UI/WebControls/TCompareValidator.php +++ b/framework/Web/UI/WebControls/TCompareValidator.php @@ -31,8 +31,8 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * type before the comparison operation is performed. The following value types are supported: * - Integer A 32-bit signed integer data type. * - Float A double-precision floating point number data type. - * - Date A date data type. The format can be specified by the - * {@link setDateFormat DateFormat} property + * - Date A date data type. The format can be specified by the + * {@link setDateFormat DateFormat} property * - String A string data type. * * Use the {@link setOperator Operator} property to specify the type of comparison @@ -46,6 +46,16 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); */ class TCompareValidator extends TBaseValidator { + /** + * Gets the name of the javascript class responsible for performing validation for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TCompareValidator'; + } + /** * @return string the data type that the values being compared are converted to before the comparison is made. Defaults to String. */ diff --git a/framework/Web/UI/WebControls/TCustomValidator.php b/framework/Web/UI/WebControls/TCustomValidator.php index 27cfa67a..32510f89 100644 --- a/framework/Web/UI/WebControls/TCustomValidator.php +++ b/framework/Web/UI/WebControls/TCustomValidator.php @@ -54,6 +54,16 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); */ class TCustomValidator extends TBaseValidator { + /** + * Gets the name of the javascript class responsible for performing validation for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TCustomValidator'; + } + /** * @return string the name of the custom client-side script function used for validation. */ diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php index ebcaace7..bd7569fc 100644 --- a/framework/Web/UI/WebControls/TDataTypeValidator.php +++ b/framework/Web/UI/WebControls/TDataTypeValidator.php @@ -36,6 +36,16 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); */ class TDataTypeValidator extends TBaseValidator { + /** + * Gets the name of the javascript class responsible for performing validation for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TDataTypeValidator'; + } + /** * @return string the data type that the values being compared are converted to before the comparison is made. Defaults to String. */ diff --git a/framework/Web/UI/WebControls/TDropDownList.php b/framework/Web/UI/WebControls/TDropDownList.php index 14a4dac4..860fe69c 100644 --- a/framework/Web/UI/WebControls/TDropDownList.php +++ b/framework/Web/UI/WebControls/TDropDownList.php @@ -38,6 +38,16 @@ class TDropDownList extends TListControl implements IPostBackDataHandler, IValid parent::addAttributesToRender($writer); } + /** + * Gets the name of the javascript class responsible for performing postback for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TDropDownList'; + } + /** * Loads user input data. * This method is primarly used by framework developers. diff --git a/framework/Web/UI/WebControls/TEmailAddressValidator.php b/framework/Web/UI/WebControls/TEmailAddressValidator.php index 3534d1d0..e1150233 100644 --- a/framework/Web/UI/WebControls/TEmailAddressValidator.php +++ b/framework/Web/UI/WebControls/TEmailAddressValidator.php @@ -35,6 +35,16 @@ class TEmailAddressValidator extends TRegularExpressionValidator */ const EMAIL_REGEXP="\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"; + /** + * Gets the name of the javascript class responsible for performing validation for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TEmailAddressValidator'; + } + /** * @return string the regular expression that determines the pattern used to validate a field. */ diff --git a/framework/Web/UI/WebControls/TListBox.php b/framework/Web/UI/WebControls/TListBox.php index 5ee3f58e..972ebbcb 100644 --- a/framework/Web/UI/WebControls/TListBox.php +++ b/framework/Web/UI/WebControls/TListBox.php @@ -47,6 +47,16 @@ class TListBox extends TListControl implements IPostBackDataHandler, IValidatabl parent::addAttributesToRender($writer); } + /** + * Gets the name of the javascript class responsible for performing postback for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TListBox'; + } + /** * Registers the list control to load post data on postback. * This method overrides the parent implementation. diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php index 2953f380..f85cc741 100644 --- a/framework/Web/UI/WebControls/TListControl.php +++ b/framework/Web/UI/WebControls/TListControl.php @@ -115,13 +115,20 @@ abstract class TListControl extends TDataBoundControl if($this->getEnabled(true) && $this->getAutoPostBack() && $page->getClientSupportsJavaScript()) { $writer->addAttribute('id',$this->getClientID()); - $this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.'.get_class($this),$this->getPostBackOptions()); + $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions()); } if(!$this->getEnabled(true) && $this->getEnabled()) $writer->addAttribute('disabled','disabled'); parent::addAttributesToRender($writer); } + /** + * Gets the name of the javascript class responsible for performing postback for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + abstract protected function getClientClassName(); + /** * @return array postback options for JS postback code */ diff --git a/framework/Web/UI/WebControls/TListControlValidator.php b/framework/Web/UI/WebControls/TListControlValidator.php index be69085d..010a7e77 100644 --- a/framework/Web/UI/WebControls/TListControlValidator.php +++ b/framework/Web/UI/WebControls/TListControlValidator.php @@ -63,6 +63,16 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); */ class TListControlValidator extends TBaseValidator { + /** + * Gets the name of the javascript class responsible for performing validation for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TListControlValidator'; + } + /** * @return integer min number of selections. Defaults to -1, meaning not set. */ @@ -195,7 +205,7 @@ class TListControlValidator extends TBaseValidator if(!$control instanceof TListControl) { throw new TConfigurationException( - 'tlistcontrolvalidator_invalid_control', + 'listcontrolvalidator_invalid_control', $this->getID(),$this->getControlToValidate(), get_class($control)); } diff --git a/framework/Web/UI/WebControls/TRadioButtonList.php b/framework/Web/UI/WebControls/TRadioButtonList.php index b0a36c9d..95725836 100644 --- a/framework/Web/UI/WebControls/TRadioButtonList.php +++ b/framework/Web/UI/WebControls/TRadioButtonList.php @@ -52,6 +52,16 @@ class TRadioButtonList extends TCheckBoxList return new TRadioButton; } + /** + * Gets the name of the javascript class responsible for performing postback for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TRadioButtonList'; + } + /** * Loads user input data. * This method is primarly used by framework developers. diff --git a/framework/Web/UI/WebControls/TRangeValidator.php b/framework/Web/UI/WebControls/TRangeValidator.php index b7387522..9d23eb5e 100644 --- a/framework/Web/UI/WebControls/TRangeValidator.php +++ b/framework/Web/UI/WebControls/TRangeValidator.php @@ -42,6 +42,16 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); */ class TRangeValidator extends TBaseValidator { + /** + * Gets the name of the javascript class responsible for performing validation for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TRangeValidator'; + } + /** * @return string the minimum value of the validation range. */ diff --git a/framework/Web/UI/WebControls/TRegularExpressionValidator.php b/framework/Web/UI/WebControls/TRegularExpressionValidator.php index e73fd5be..3099514b 100644 --- a/framework/Web/UI/WebControls/TRegularExpressionValidator.php +++ b/framework/Web/UI/WebControls/TRegularExpressionValidator.php @@ -49,6 +49,16 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); */ class TRegularExpressionValidator extends TBaseValidator { + /** + * Gets the name of the javascript class responsible for performing validation for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TRegularExpressionValidator'; + } + /** * @return string the regular expression that determines the pattern used to validate a field. */ diff --git a/framework/Web/UI/WebControls/TRequiredFieldValidator.php b/framework/Web/UI/WebControls/TRequiredFieldValidator.php index 04e333eb..b8a939ad 100644 --- a/framework/Web/UI/WebControls/TRequiredFieldValidator.php +++ b/framework/Web/UI/WebControls/TRequiredFieldValidator.php @@ -21,7 +21,7 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); * TRequiredFieldValidator makes the associated input control a required field. * The input control fails validation if its value does not change from * the {@link setInitialValue InitialValue} property upon losing focus. - * + * * Validation will also succeed if input is of TListControl type and the number * of selected values different from the initial value is greater than zero. * @@ -32,6 +32,16 @@ Prado::using('System.Web.UI.WebControls.TBaseValidator'); */ class TRequiredFieldValidator extends TBaseValidator { + /** + * Gets the name of the javascript class responsible for performing validation for this control. + * This method overrides the parent implementation. + * @return string the javascript class name + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TRequiredFieldValidator'; + } + /** * @return string the initial value of the associated input control. Defaults to empty string. * If the associated input control does not change from this initial value @@ -56,11 +66,11 @@ class TRequiredFieldValidator extends TBaseValidator * This method overrides the parent's implementation. * The validation succeeds if the input component changes its data * from the {@link getInitialValue InitialValue} or the input control is not given. - * + * * Validation will also succeed if input is of TListControl type and the * number of selected values different from the initial value is greater * than zero. - * + * * @return boolean whether the validation succeeds */ protected function evaluateIsValid() -- cgit v1.2.3