Permalink
Browse files

refactorings

  • Loading branch information...
dg committed Dec 2, 2018
1 parent 97b8877 commit 2210656d26e8218b5a7436066dd45598fd594542
Showing with 18 additions and 5 deletions.
  1. +1 −3 examples/manual-rendering.php
  2. +5 −2 src/Forms/Controls/SelectBox.php
  3. +12 −0 tests/Forms/Helpers.exportRules.phpt
@@ -30,9 +30,7 @@
'f' => 'female',
]);
$form->addText('email')
->setRequired(false)
->addRule($form::EMAIL, 'Incorrect email address');
$form->addEmail('email');
$form->addSubmit('submit');
@@ -34,8 +34,11 @@ public function __construct($label = null, array $items = null)
{
parent::__construct($label, $items);
$this->setOption('type', 'select');
$this->addCondition(Nette\Forms\Form::BLANK)
->addRule([$this, 'isOk'], Nette\Forms\Validator::$messages[self::VALID]);
$this->addCondition(function () {
return $this->prompt === false
&& $this->options
&& $this->control->size < 2;
})->addRule(Nette\Forms\Form::FILLED, Nette\Forms\Validator::$messages[self::VALID]);
}
@@ -38,6 +38,18 @@ test(function () {
});
test(function () {
$form = new Form;
$input = $form->addText('text');
$input->setRequired(true);
$input->addRule(Form::EMAIL);
Assert::same([
['op' => ':filled', 'msg' => 'This field is required.'],
['op' => ':email', 'msg' => 'Please enter a valid email address.'],
], Helpers::exportRules($input->getRules()));
});
test(function () {
$form = new Form;
$input = $form->addText('text');

0 comments on commit 2210656

Please sign in to comment.