File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -260,6 +260,15 @@ public function check(): bool
260260 }
261261
262262
263+ /**
264+ * Clear all validation rules.
265+ */
266+ public function reset (): void
267+ {
268+ $ this ->rules = [];
269+ }
270+
271+
263272 /**
264273 * Validates single rule.
265274 */
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Nette \Forms \Form ;
4+ use Tester \Assert ;
5+
6+
7+ require __DIR__ . '/../bootstrap.php ' ;
8+
9+
10+ test (function () {
11+ $ form = new Form ;
12+ $ input = $ form ->addText ('text ' );
13+ $ input ->addCondition (false )
14+ ->setRequired ();
15+
16+ Assert::count (1 , iterator_to_array ($ input ->getRules ()));
17+ $ input ->getRules ()->reset ();
18+
19+ Assert::count (0 , iterator_to_array ($ input ->getRules ()));
20+ });
21+
22+
23+ test (function () {
24+ $ form = new Form ;
25+ $ input1 = $ form ->addText ('text1 ' );
26+ $ input2 = $ form ->addText ('text2 ' );
27+ $ input2 ->addConditionOn ($ input1 , $ form ::FILLED )
28+ ->addRule ($ form ::BLANK );
29+
30+ Assert::count (0 , iterator_to_array ($ input1 ->getRules ()));
31+ Assert::count (1 , iterator_to_array ($ input2 ->getRules ()));
32+ $ input2 ->getRules ()->reset ();
33+
34+ Assert::count (0 , iterator_to_array ($ input2 ->getRules ()));
35+ });
You can’t perform that action at this time.
0 commit comments