addRule() public method

Adds a validation rule.
public addRule ( $validator, $message = NULL, $arg = NULL ) : self
return self
コード例 #1
0
ファイル: DefaultMapper.php プロジェクト: voda/formbuilder
 /**
  * Add default conditions.
  * Supports: required, min/maxLength, min, max
  *
  * @param \Nette\Forms\Controls\BaseControl $input
  * @param array $conditions
  */
 protected function addConditions(\Nette\Forms\Controls\BaseControl $input, array $conditions)
 {
     foreach ($conditions as $key => $value) {
         switch ($key) {
             case 'required':
                 $input->setRequired();
                 break;
             case 'maxLength':
                 $input->addRule(Builder\EntityForm::MAX_LENGTH, null, $value);
                 break;
             case 'minLength':
                 $input->addRule(Builder\EntityForm::MIN_LENGTH, null, $value);
                 break;
             default:
                 break;
         }
     }
     if (isset($conditions['min']) || isset($conditions['max'])) {
         $input->addRule(Builder\EntityForm::RANGE, null, array(isset($conditions['min']) ? $conditions['min'] : null, isset($conditions['max']) ? $conditions['max'] : null));
     }
 }
コード例 #2
0
ファイル: TextBase.php プロジェクト: bazo/Tatami
 public function addRule($operation, $message = NULL, $arg = NULL)
 {
     if ($operation === Form::FLOAT) {
         $this->addFilter(callback(__CLASS__, 'filterFloat'));
     }
     return parent::addRule($operation, $message, $arg);
 }
コード例 #3
0
ファイル: TextBase.php プロジェクト: luminousinfoways/pccfoas
 public function addRule($validator, $message = NULL, $arg = NULL)
 {
     if ($validator === Form::LENGTH || $validator === Form::MAX_LENGTH) {
         $tmp = is_array($arg) ? $arg[1] : $arg;
         if (is_scalar($tmp)) {
             $this->control->maxlength = isset($this->control->maxlength) ? min($this->control->maxlength, $tmp) : $tmp;
         }
     }
     return parent::addRule($validator, $message, $arg);
 }
コード例 #4
0
ファイル: TextBase.php プロジェクト: ppwalks33/cleansure
 public function addRule($operation, $message = NULL, $arg = NULL)
 {
     if ($operation === Form::FLOAT) {
         $this->addFilter(array(__CLASS__, 'filterFloat'));
     } elseif ($operation === Form::LENGTH || $operation === Form::MAX_LENGTH) {
         $tmp = is_array($arg) ? $arg[1] : $arg;
         $this->control->maxlength = is_scalar($tmp) ? $tmp : NULL;
     }
     return parent::addRule($operation, $message, $arg);
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function addRule($validator, $message = NULL, $arg = NULL)
 {
     return $this->wrappedControl->addRule($validator, $message, $arg);
 }
コード例 #6
0
ファイル: DateInput.php プロジェクト: pt24/DateInput
 public function addRule($operation, $message = null, $arg = null)
 {
     if ($operation === \Nette\Forms\Form::RANGE) {
         $this->range['min'] = $this->normalizeDate($arg[0]);
         $this->range['max'] = $this->normalizeDate($arg[1]);
         $operation = __CLASS__ . '::validateDateInputRange';
         $arg[0] = $this->formatDate($arg[0]);
         $arg[1] = $this->formatDate($arg[1]);
     } elseif ($operation === \Nette\Forms\Form::VALID) {
         $operation = __CLASS__ . '::validateDateInputValid';
     }
     return parent::addRule($operation, $message, $arg);
 }
コード例 #7
0
ファイル: TextBase.php プロジェクト: Johnik010/rezervace
 public function addRule($operation, $message = NULL, $arg = NULL)
 {
     if ($operation === Form::LENGTH || $operation === Form::MAX_LENGTH) {
         $tmp = is_array($arg) ? $arg[1] : $arg;
         $this->control->maxlength = is_scalar($tmp) ? $tmp : NULL;
     }
     return parent::addRule($operation, $message, $arg);
 }
コード例 #8
0
 /**
  * @param BaseControl $control
  * @param string      $rule
  * @param string      $message
  * @param mixed       $arg
  */
 protected function addNetteRule(BaseControl $control, $rule, $message, $arg = NULL)
 {
     $control->addRule($rule, $message, $arg);
 }
コード例 #9
0
ファイル: loader.php プロジェクト: JanTvrdik/NetteExtras
getControl(){$control=parent::getControl();foreach($this->getRules()as$rule){if($rule->type===Nette\Forms\Rule::VALIDATOR&&!$rule->isNegative&&($rule->operation===Form::LENGTH||$rule->operation===Form::MAX_LENGTH)){$control->maxlength=is_array($rule->arg)?$rule->arg[1]:$rule->arg;}}if($this->emptyValue!==''){$control->data('nette-empty-value',$this->translate($this->emptyValue));}return$control;}function
addRule($operation,$message=NULL,$arg=NULL){if($operation===Form::FLOAT){$this->addFilter(callback(__CLASS__,'filterFloat'));}return
parent::addRule($operation,$message,$arg);}static
コード例 #10
0
 public function addRule($operation, $message = null, $arg = null)
 {
     if ($operation === Form::FLOAT) {
         $this->addFilter(array(__CLASS__, 'filterFloat'));
     }
     return parent::addRule($operation, $message, $arg);
 }
コード例 #11
0
ファイル: DateInput.php プロジェクト: BroukPytlik/agility
 /**
  * Adds a validation rule.
  * @param  mixed      rule type
  * @param  string     message to display for invalid data
  * @param  mixed      optional rule arguments
  * @return BaseControl  provides a fluent interface
  */
 public function addRule($operation, $message = NULL, $arg = NULL)
 {
     if ($operation === \Nette\Forms\Form::RANGE) {
         $this->range['min'] = $arg[0];
         $this->range['max'] = $arg[1];
         $operation = ':dateInputRange';
         $arg[0] = $this->formatDate($arg[0]);
         $arg[1] = $this->formatDate($arg[1]);
     } elseif ($operation === \Nette\Forms\Form::VALID) {
         $operation = ':dateInputValid';
     }
     return parent::addRule($operation, $message, $arg);
 }
コード例 #12
0
 /**
  * @param $validator
  * @param null $message
  * @param array|null $arg
  *
  * @return $this|BaseControl
  *
  * @throws DatePickerException
  */
 public function addRule($validator, $message = NULL, $arg = NULL)
 {
     // check for disabled dates
     if ($validator == self::DISABLED_DATES) {
         if (!is_array($arg)) {
             throw new DatePickerException('Rule argument is not valid! Array of \\DateTime objects is expected. ' . get_class($arg) . ' given.');
         }
         foreach ($arg as $date) {
             if ($date instanceof \DateTime) {
                 // add only instances of DateTime
                 $this->setDisabledDate($date);
             }
         }
         parent::addRule($validator, $message, $this->datesDisabled);
     } elseif ($validator == self::DISABLED_DAYS) {
         if (is_array($arg)) {
             // filter array values
             $arg = array_filter($arg, 'Vojtys\\Forms\\DatePicker\\DatePickerBase::isInRange');
             $this->setDaysOfWeekDisabled($arg);
             parent::addRule($validator, $message, $arg);
         } else {
             throw new DatePickerException('Rule argument is not valid! Array is expected ' . get_class($arg) . ' given.');
         }
     } elseif ($validator == self::DATE_TIME_MIN) {
         if ($arg instanceof \DateTime) {
             $this->setStartDate($arg);
             // set datepicker option
             parent::addRule($validator, $message, $arg);
         } else {
             throw new DatePickerException('Rule argument is not valid! \\DateTime object is expected. ' . get_class($arg) . ' given.');
         }
     } elseif ($validator == self::DATE_TIME_MAX) {
         if ($arg instanceof \DateTime) {
             $this->setEndDate($arg);
             // set datepicker option
             parent::addRule($validator, $message, $arg);
         } else {
             throw new DatePickerException('Rule argument is not valid! \\DateTime object is expected. ' . get_class($arg) . ' given.');
         }
     } else {
         parent::addRule($validator, $message, $arg);
     }
     return $this;
 }