File tree Expand file tree Collapse file tree 4 files changed +25
-0
lines changed Expand file tree Collapse file tree 4 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,15 @@ public function __construct(array $args = array())
3232 }
3333 }
3434
35+ public function toNative ($ value )
36+ {
37+ $ value = parent ::toNative ($ value );
38+
39+ $ value = trim ((string ) $ value );
40+
41+ return !empty ($ value ) ? $ value : '' ;
42+ }
43+
3544 /**
3645 * Return extra minlength and maxlength attrs to be added to the input in HTML.
3746 *
Original file line number Diff line number Diff line change @@ -17,4 +17,11 @@ public function __construct(array $args = array())
1717
1818 $ this ->validators [] = new EmailValidator ();
1919 }
20+
21+ public function toNative ($ value )
22+ {
23+ $ value = parent ::toNative ($ value );
24+
25+ return filter_var ($ value , FILTER_SANITIZE_EMAIL );
26+ }
2027}
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ public function __construct(array $args = array())
3535
3636 public function toNative ($ value )
3737 {
38+ $ value = filter_var ($ value , FILTER_SANITIZE_NUMBER_INT );
39+
3840 if (is_numeric ($ value )) {
3941 return intval ($ value );
4042 } else {
Original file line number Diff line number Diff line change @@ -51,4 +51,11 @@ public function testWidgetAttrs()
5151 $ expected = array ("minlength " => 10 , "maxlength " => 20 );
5252 $ this ->assertEquals ($ expected , $ this ->field ->widgetAttrs (null ));
5353 }
54+
55+ public function testToNative ()
56+ {
57+ $ this ->assertEquals ("text " , $ this ->field ->toNative ("text " ));
58+ $ this ->assertEquals ("text " , $ this ->field ->toNative (" text " ));
59+ $ this ->assertEquals ("" , $ this ->field ->toNative (0 ));
60+ }
5461}
You can’t perform that action at this time.
0 commit comments