本文整理汇总了PHP中Nette\Forms\Controls\BaseControl::addRule方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseControl::addRule方法的具体用法?PHP BaseControl::addRule怎么用?PHP BaseControl::addRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Controls\BaseControl
的用法示例。
在下文中一共展示了BaseControl::addRule方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addConditions
/**
* 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: addRule
public function addRule($operation, $message = NULL, $arg = NULL)
{
if ($operation === Form::FLOAT) {
$this->addFilter(callback(__CLASS__, 'filterFloat'));
}
return parent::addRule($operation, $message, $arg);
}
示例3: addRule
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: addRule
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: addRule
/**
* {@inheritdoc}
*/
public function addRule($validator, $message = NULL, $arg = NULL)
{
return $this->wrappedControl->addRule($validator, $message, $arg);
}
示例6: addRule
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: addRule
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: addNetteRule
/**
* @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:
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: addRule
public function addRule($operation, $message = null, $arg = null)
{
if ($operation === Form::FLOAT) {
$this->addFilter(array(__CLASS__, 'filterFloat'));
}
return parent::addRule($operation, $message, $arg);
}
示例11: addRule
/**
* 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: addRule
/**
* @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;
}