File tree Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -96,11 +96,8 @@ public function setMaxLength($length)
9696 */
9797 public function addFilter ($ filter )
9898 {
99- Nette \Utils \Callback::check ($ filter );
100- return parent ::addRule (function ($ control ) use ($ filter ) {
101- $ control ->setValue ( call_user_func ($ filter , $ control ->getValue ()) );
102- return TRUE ;
103- });
99+ $ this ->rules ->addFilter ($ filter );
100+ return $ this ;
104101 }
105102
106103
Original file line number Diff line number Diff line change @@ -151,6 +151,24 @@ public function endCondition()
151151 }
152152
153153
154+ /**
155+ * Adds a filter callback.
156+ * @param callable
157+ * @return self
158+ */
159+ public function addFilter ($ filter )
160+ {
161+ Nette \Utils \Callback::check ($ filter );
162+ $ this ->rules [] = $ rule = new Rule ;
163+ $ rule ->control = $ this ->control ;
164+ $ rule ->validator = function ($ control ) use ($ filter ) {
165+ $ control ->setValue ( call_user_func ($ filter , $ control ->getValue ()) );
166+ return TRUE ;
167+ };
168+ return $ this ;
169+ }
170+
171+
154172 /**
155173 * Toggles HTML element visibility.
156174 * @param string element id
Original file line number Diff line number Diff line change @@ -173,3 +173,17 @@ test(function() { // filter
173173 $ input ->validate ();
174174 Assert::same ( 'olleh ' , $ input ->getValue () );
175175});
176+
177+
178+ test (function () { // filter in condition
179+ $ _POST = array ('text ' => 'hello ' );
180+
181+ $ form = new Form ;
182+ $ input = $ form ->addText ('text ' );
183+ $ input ->addCondition ($ form ::FILLED )
184+ ->addFilter ('strrev ' );
185+
186+ Assert::same ( 'hello ' , $ input ->getValue () );
187+ $ input ->validate ();
188+ Assert::same ( 'olleh ' , $ input ->getValue () );
189+ });
You can’t perform that action at this time.
0 commit comments