Navigation Menu

Skip to content

Commit

Permalink
Rules: added reset method
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jun 4, 2018
1 parent a5e96ad commit 4994616
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Forms/Rules.php
Expand Up @@ -277,6 +277,15 @@ public function check()
}


/**
* Clear all validation rules.
*/
public function reset()
{
$this->rules = [];
}


/**
* Validates single rule.
* @return bool
Expand Down
35 changes: 35 additions & 0 deletions tests/Forms/Rules.reset.phpt
@@ -0,0 +1,35 @@
<?php

use Nette\Forms\Form;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


test(function () {
$form = new Form;
$input = $form->addText('text');
$input->addCondition(false)
->setRequired();

Assert::count(1, iterator_to_array($input->getRules()));
$input->getRules()->reset();

Assert::count(0, iterator_to_array($input->getRules()));
});


test(function () {
$form = new Form;
$input1 = $form->addText('text1');
$input2 = $form->addText('text2');
$input2->addConditionOn($input1, $form::FILLED)
->addRule($form::BLANK);

Assert::count(0, iterator_to_array($input1->getRules()));
Assert::count(1, iterator_to_array($input2->getRules()));
$input2->getRules()->reset();

Assert::count(0, iterator_to_array($input2->getRules()));
});

0 comments on commit 4994616

Please sign in to comment.