File tree 2 files changed +44
-0
lines changed
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
260
260
}
261
261
262
262
263
+ /**
264
+ * Clear all validation rules.
265
+ */
266
+ public function reset (): void
267
+ {
268
+ $ this ->rules = [];
269
+ }
270
+
271
+
263
272
/**
264
273
* Validates single rule.
265
274
*/
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