[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Web/UI/WebControls/ -> TCustomValidator.php (source)

   1  <?php
   2  /**
   3   * TCustomValidator class file
   4   *
   5   * @author Qiang Xue <qiang.xue@gmail.com>
   6   * @link http://www.pradosoft.com/
   7   * @copyright Copyright &copy; 2005 PradoSoft
   8   * @license http://www.pradosoft.com/license/
   9   * @version $Id: TCustomValidator.php 1397 2006-09-07 07:55:53Z wei $
  10   * @package System.Web.UI.WebControls
  11   */
  12  
  13  /**
  14   * Using TBaseValidator class
  15   */
  16  Prado::using('System.Web.UI.WebControls.TBaseValidator');
  17  
  18  /**
  19   * TCustomValidator class
  20   *
  21   * TCustomValidator performs user-defined validation (either
  22   * server-side or client-side or both) on an input component.
  23   *
  24   * To create a server-side validation function, provide a handler for
  25   * the {@link onServerValidate OnServerValidate} event that performs the validation.
  26   * The data string of the input control to validate can be accessed
  27   * by {@link TServerValidateEventParameter::getValue Value} of the event parameter.
  28   * The result of the validation should be stored in the
  29   * {@link TServerValidateEventParameter::getIsValid IsValid} property of the event
  30   * parameter.
  31   *
  32   * To create a client-side validation function, add the client-side
  33   * validation javascript function to the page template.
  34   * The function should have the following signature:
  35   * <code>
  36   * <script type="text/javascript"><!--
  37   * function ValidationFunctionName(sender, parameter)
  38   * {
  39   *    // if(parameter == ...)
  40   *    //    return true;
  41   *    // else
  42   *    //    return false;
  43   * }
  44   * --></script>
  45   * </code>
  46   * Use the {@link setClientValidationFunction ClientValidationFunction} property
  47   * to specify the name of the client-side validation script function associated
  48   * with the TCustomValidator.
  49   *
  50   * @author Qiang Xue <qiang.xue@gmail.com>
  51   * @version $Id: TCustomValidator.php 1397 2006-09-07 07:55:53Z wei $
  52   * @package System.Web.UI.WebControls
  53   * @since 3.0
  54   */
  55  class TCustomValidator extends TBaseValidator
  56  {
  57      /**
  58       * Gets the name of the javascript class responsible for performing validation for this control.
  59       * This method overrides the parent implementation.
  60       * @return string the javascript class name
  61       */
  62  	protected function getClientClassName()
  63      {
  64          return 'Prado.WebUI.TCustomValidator';
  65      }
  66  
  67      /**
  68       * @return string the name of the custom client-side script function used for validation.
  69       */
  70  	public function getClientValidationFunction()
  71      {
  72          return $this->getViewState('ClientValidationFunction','');
  73      }
  74  
  75      /**
  76       * Sets the name of the custom client-side script function used for validation.
  77       * @param string the script function name
  78       */
  79  	public function setClientValidationFunction($value)
  80      {
  81          $this->setViewState('ClientValidationFunction',$value,'');
  82      }
  83  
  84      /**
  85       * This method overrides the parent's implementation.
  86       * The validation succeeds if {@link onServerValidate} returns true.
  87       * @return boolean whether the validation succeeds
  88       */
  89  	public function evaluateIsValid()
  90      {
  91          $value=$this->getValidationValue($this->getValidationTarget());
  92          return $this->onServerValidate($value);
  93      }
  94  
  95      /**
  96       * This method is invoked when the server side validation happens.
  97       * It will raise the <b>OnServerValidate</b> event.
  98       * The method also allows derived classes to handle the event without attaching a delegate.
  99       * <b>Note</b> The derived classes should call parent implementation
 100       * to ensure the <b>OnServerValidate</b> event is raised.
 101       * @param string the value to be validated
 102       * @return boolean whether the value is valid
 103       */
 104  	public function onServerValidate($value)
 105      {
 106          $param=new TServerValidateEventParameter($value,true);
 107          $this->raiseEvent('OnServerValidate',$this,$param);
 108          return $param->getIsValid();
 109      }
 110  
 111  
 112      /**
 113       * Returns an array of javascript validator options.
 114       * @return array javascript validator options.
 115       */
 116  	protected function getClientScriptOptions()
 117      {
 118          $options=parent::getClientScriptOptions();
 119          if(($clientJs=$this->getClientValidationFunction())!=='')
 120              $options['ClientValidationFunction']=$clientJs;
 121          return $options;
 122      }
 123      
 124      /**
 125       * Only register the client-side validator if 
 126       * {@link setClientValidationFunction ClientValidationFunction} is set.
 127       */
 128  	protected function registerClientScriptValidator()
 129      {
 130          if($this->getClientValidationFunction()!=='')
 131              parent::registerClientScriptValidator();
 132      }
 133  }
 134  
 135  /**
 136   * TServerValidateEventParameter class
 137   *
 138   * TServerValidateEventParameter encapsulates the parameter data for
 139   * <b>OnServerValidate</b> event of TCustomValidator components.
 140   *
 141   * @author Qiang Xue <qiang.xue@gmail.com>
 142   * @version $Id: TCustomValidator.php 1397 2006-09-07 07:55:53Z wei $
 143   * @package System.Web.UI.WebControls
 144   * @since 3.0
 145   */
 146  class TServerValidateEventParameter extends TEventParameter
 147  {
 148      /**
 149       * the value to be validated
 150       * @var string
 151       */
 152      private $_value='';
 153      /**
 154       * whether the value is valid
 155       * @var boolean
 156       */
 157      private $_isValid=true;
 158  
 159      /**
 160       * Constructor.
 161       * @param string property value to be validated
 162       * @param boolean whether the value is valid
 163       */
 164  	public function __construct($value,$isValid)
 165      {
 166          $this->_value=$value;
 167          $this->setIsValid($isValid);
 168      }
 169  
 170      /**
 171       * @return string value to be validated
 172       */
 173  	public function getValue()
 174      {
 175          return $this->_value;
 176      }
 177  
 178      /**
 179       * @return boolean whether the value is valid
 180       */
 181  	public function getIsValid()
 182      {
 183          return $this->_isValid;
 184      }
 185  
 186      /**
 187       * @param boolean whether the value is valid
 188       */
 189  	public function setIsValid($value)
 190      {
 191          $this->_isValid=TPropertyValue::ensureBoolean($value);
 192      }
 193  }
 194  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7