1616 * @author Zura Sekhniashvili <[email protected] > 1717 * @package core\form
1818 */
19- class Field
19+ class Field extends BaseField
2020{
2121 const TYPE_TEXT = 'text ' ;
2222 const TYPE_PASSWORD = 'password ' ;
23-
24- public Model $ model ;
25- public string $ attribute ;
26- public string $ type ;
23+ const TYPE_FILE = 'file ' ;
2724
2825 /**
2926 * Field constructor.
@@ -34,25 +31,16 @@ class Field
3431 public function __construct (Model $ model , string $ attribute )
3532 {
3633 $ this ->type = self ::TYPE_TEXT ;
37- $ this ->model = $ model ;
38- $ this ->attribute = $ attribute ;
34+ parent ::__construct ($ model , $ attribute );
3935 }
4036
41- public function __toString ()
37+ public function renderInput ()
4238 {
43- return sprintf ('<div class="form-group">
44- <label>%s</label>
45- <input type="%s" class="form-control%s" name="%s" value="%s">
46- <div class="invalid-feedback">
47- %s
48- </div>
49- </div> ' ,
50- $ this ->model ->getLabel ($ this ->attribute ),
39+ return sprintf ('<input type="%s" class="form-control%s" name="%s" value="%s"> ' ,
5140 $ this ->type ,
5241 $ this ->model ->hasError ($ this ->attribute ) ? ' is-invalid ' : '' ,
5342 $ this ->attribute ,
5443 $ this ->model ->{$ this ->attribute },
55- $ this ->model ->getFirstError ($ this ->attribute )
5644 );
5745 }
5846
@@ -61,4 +49,10 @@ public function passwordField()
6149 $ this ->type = self ::TYPE_PASSWORD ;
6250 return $ this ;
6351 }
52+
53+ public function fileField ()
54+ {
55+ $ this ->type = self ::TYPE_FILE ;
56+ return $ this ;
57+ }
6458}
0 commit comments