File tree Expand file tree Collapse file tree 4 files changed +25
-13
lines changed Expand file tree Collapse file tree 4 files changed +25
-13
lines changed Original file line number Diff line number Diff line change @@ -33,12 +33,8 @@ public function __construct($label = NULL)
3333 */
3434 public function getControl ()
3535 {
36- $ value = $ this ->getValue ();
37- if ($ value === '' ) {
38- $ value = $ this ->translate ($ this ->emptyValue );
39- }
4036 return parent ::getControl ()
41- ->setText ($ value );
37+ ->setText ($ this -> getRenderedValue () );
4238 }
4339
4440}
Original file line number Diff line number Diff line change @@ -111,6 +111,17 @@ public function getControl()
111111 }
112112
113113
114+ /**
115+ * @return string|NULL
116+ */
117+ protected function getRenderedValue ()
118+ {
119+ return $ this ->rawValue === ''
120+ ? ($ this ->emptyValue === '' ? NULL : $ this ->translate ($ this ->emptyValue ))
121+ : $ this ->rawValue ;
122+ }
123+
124+
114125 public function addRule ($ validator , $ message = NULL , $ arg = NULL )
115126 {
116127 if ($ validator === Form::LENGTH || $ validator === Form::MAX_LENGTH ) {
Original file line number Diff line number Diff line change @@ -57,14 +57,10 @@ public function setType($type)
5757 */
5858 public function getControl ()
5959 {
60- $ input = parent ::getControl ();
61- if ($ input ->type !== 'password ' && ($ this ->rawValue !== '' || $ this ->emptyValue !== '' )) {
62- $ input ->value = $ this ->rawValue === ''
63- ? $ this ->translate ($ this ->emptyValue )
64- : $ this ->rawValue ;
65- }
66- $ input ->type = $ input ->type ?: 'text ' ;
67- return $ input ;
60+ return parent ::getControl ()->addAttributes ([
61+ 'value ' => $ this ->control ->type === 'password ' ? $ this ->control ->value : $ this ->getRenderedValue (),
62+ 'type ' => $ this ->control ->type ?: 'text ' ,
63+ ]);
6864 }
6965
7066
Original file line number Diff line number Diff line change @@ -97,3 +97,12 @@ test(function () { // rendering options
9797 $ input ->getControl ();
9898 Assert::true ($ input ->getOption ('rendered ' ));
9999});
100+
101+
102+ test (function () { // setEmptyValue
103+ $ form = new Form ;
104+ $ input = $ form ->addTextArea ('text ' )
105+ ->setEmptyValue ('empty ' );
106+
107+ Assert::same ('<textarea name="text" id="frm-text" data-nette-empty-value="empty">empty </textarea> ' , (string ) $ input ->getControl ());
108+ });
You can’t perform that action at this time.
0 commit comments