File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-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+ declare (strict_types=1 );
4+
5+ use Nette \Forms \Form ;
6+ use Tester \Assert ;
7+
8+
9+ require __DIR__ . '/../bootstrap.php ' ;
10+
11+
12+ test (function () {
13+ $ form = new Form ;
14+ $ input = $ form ->addText ('text ' );
15+ $ input ->addCondition (false )
16+ ->setRequired ();
17+
18+ Assert::count (1 , iterator_to_array ($ input ->getRules ()));
19+ $ input ->getRules ()->reset ();
20+
21+ Assert::count (0 , iterator_to_array ($ input ->getRules ()));
22+ });
23+
24+
25+ test (function () {
26+ $ form = new Form ;
27+ $ input1 = $ form ->addText ('text1 ' );
28+ $ input2 = $ form ->addText ('text2 ' );
29+ $ input2 ->addConditionOn ($ input1 , $ form ::FILLED )
30+ ->addRule ($ form ::BLANK );
31+
32+ Assert::count (0 , iterator_to_array ($ input1 ->getRules ()));
33+ Assert::count (1 , iterator_to_array ($ input2 ->getRules ()));
34+ $ input2 ->getRules ()->reset ();
35+
36+ Assert::count (0 , iterator_to_array ($ input2 ->getRules ()));
37+ });
You can’t perform that action at this time.
0 commit comments