16
16
* @author Zura Sekhniashvili <zurasekhniashvili@gmail.com>
17
17
* @package core\form
18
18
*/
19
- class Field
19
+ class Field extends BaseField
20
20
{
21
21
const TYPE_TEXT = 'text ' ;
22
22
const TYPE_PASSWORD = 'password ' ;
23
-
24
- public Model $ model ;
25
- public string $ attribute ;
26
- public string $ type ;
23
+ const TYPE_FILE = 'file ' ;
27
24
28
25
/**
29
26
* Field constructor.
@@ -34,25 +31,16 @@ class Field
34
31
public function __construct (Model $ model , string $ attribute )
35
32
{
36
33
$ this ->type = self ::TYPE_TEXT ;
37
- $ this ->model = $ model ;
38
- $ this ->attribute = $ attribute ;
34
+ parent ::__construct ($ model , $ attribute );
39
35
}
40
36
41
- public function __toString ()
37
+ public function renderInput ()
42
38
{
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"> ' ,
51
40
$ this ->type ,
52
41
$ this ->model ->hasError ($ this ->attribute ) ? ' is-invalid ' : '' ,
53
42
$ this ->attribute ,
54
43
$ this ->model ->{$ this ->attribute },
55
- $ this ->model ->getFirstError ($ this ->attribute )
56
44
);
57
45
}
58
46
@@ -61,4 +49,10 @@ public function passwordField()
61
49
$ this ->type = self ::TYPE_PASSWORD ;
62
50
return $ this ;
63
51
}
52
+
53
+ public function fileField ()
54
+ {
55
+ $ this ->type = self ::TYPE_FILE ;
56
+ return $ this ;
57
+ }
64
58
}
0 commit comments