本文整理汇总了PHP中Nette\Forms\Controls\BaseControl::setRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseControl::setRequired方法的具体用法?PHP BaseControl::setRequired怎么用?PHP BaseControl::setRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Controls\BaseControl
的用法示例。
在下文中一共展示了BaseControl::setRequired方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolveRequiring
/**
* @param \Nette\Forms\Controls\BaseControl $control
* @param string|null $errorMessage
* @param bool|callable $requiring
*/
private function resolveRequiring(\Nette\Forms\Controls\BaseControl $control, $errorMessage = null, $requiring = false)
{
if ($requiring === true) {
$control->setRequired($errorMessage !== null ? $errorMessage : true);
} elseif (is_callable($requiring)) {
$condition = $requiring($control);
if (!$condition instanceof \Nette\Forms\Rules) {
throw new RequiredFormFieldResolutionException('Requiring call must return instance of \\Nette\\Forms\\Rules.');
}
$condition->setRequired($errorMessage !== null ? $errorMessage : true);
}
}
示例2: 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));
}
}
示例3: setRequired
/**
* {@inheritdoc}
*/
public function setRequired($value = TRUE)
{
$this->wrappedControl->setRequired($value);
return $this;
}
示例4: setRequired
/**
* @param string|bool $message
* @return \Nella\Forms\DateTime\DateInput
*/
public function setRequired($message = TRUE)
{
if ($message !== FALSE && !is_string($message)) {
throw new \Nette\InvalidArgumentException('Message must be string');
}
parent::setRequired($message);
if ($message !== FALSE) {
$this->addCondition(Form::FILLED)->addRule(function (DateInput $control) {
return $this->validateDate($control);
}, $message);
}
return $this;
}