|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Helmut\Forms\Fields\Text; |
|
4
|
|
|
|
|
5
|
|
|
use Helmut\Forms\Field; |
|
6
|
|
|
use Helmut\Forms\Utility\Validate; |
|
7
|
|
|
|
|
8
|
|
|
class Text extends Field { |
|
9
|
|
|
|
|
10
|
|
|
protected $value = ''; |
|
11
|
|
|
protected $width = '100%'; |
|
12
|
|
|
|
|
13
|
|
|
public function setWidth($width) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->width = $width; |
|
16
|
|
|
return $this; |
|
17
|
|
|
} |
|
18
|
15 |
|
|
|
19
|
|
|
public function getValue() |
|
20
|
15 |
|
{ |
|
21
|
|
|
return $this->value; |
|
22
|
|
|
} |
|
23
|
29 |
|
|
|
24
|
|
|
public function getButtonName() |
|
25
|
29 |
|
{ |
|
26
|
|
|
// |
|
27
|
|
|
} |
|
28
|
8 |
|
|
|
29
|
|
|
public function renderWith() |
|
30
|
8 |
|
{ |
|
31
|
|
|
return [ |
|
32
|
|
|
'value' => $this->value, |
|
33
|
25 |
|
'width' => $this->width, |
|
34
|
|
|
]; |
|
35
|
25 |
|
} |
|
36
|
25 |
|
|
|
37
|
|
|
public function setValueFromDefault() |
|
38
|
1 |
|
{ |
|
39
|
|
|
$this->value = $this->default; |
|
40
|
1 |
|
} |
|
41
|
1 |
|
|
|
42
|
|
|
public function setValueFromModel($model) |
|
43
|
2 |
|
{ |
|
44
|
|
|
if (property_exists($model, $this->name)) $this->value = $model->{$this->name}; |
|
45
|
2 |
|
} |
|
46
|
2 |
|
|
|
47
|
|
|
public function setValueFromRequest($request) |
|
48
|
1 |
|
{ |
|
49
|
|
|
$this->value = $request->get($this->name); |
|
50
|
1 |
|
} |
|
51
|
1 |
|
|
|
52
|
|
|
public function fillModelWithValue($model) |
|
53
|
11 |
|
{ |
|
54
|
|
|
if (property_exists($model, $this->name)) $model->{$this->name} = $this->value; |
|
55
|
11 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function validateRequired() |
|
58
|
1 |
|
{ |
|
59
|
|
|
return Validate::required($this->value); |
|
60
|
1 |
|
} |
|
61
|
1 |
|
|
|
62
|
|
|
public function validateBetween($min, $max) |
|
63
|
|
|
{ |
|
64
|
1 |
|
return Validate::stringMin($this->value, $min) |
|
65
|
|
|
&& Validate::stringMax($this->value, $max); |
|
66
|
1 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function validateMax($max) |
|
69
|
1 |
|
{ |
|
70
|
|
|
return Validate::stringMax($this->value, $max); |
|
71
|
1 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function validateMin($min) |
|
74
|
1 |
|
{ |
|
75
|
|
|
return Validate::stringMin($this->value, $min); |
|
76
|
1 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function validateAlpha() |
|
79
|
1 |
|
{ |
|
80
|
|
|
return Validate::alpha($this->value); |
|
81
|
1 |
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function validateAlphaNum() |
|
84
|
1 |
|
{ |
|
85
|
|
|
return Validate::alphaNum($this->value); |
|
86
|
1 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function validateAlphaDash() |
|
89
|
1 |
|
{ |
|
90
|
|
|
return Validate::alphaDash($this->value); |
|
91
|
1 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function validateIn($values = []) |
|
94
|
1 |
|
{ |
|
95
|
|
|
return Validate::in($this->value, $values); |
|
96
|
1 |
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function validateNotIn($values = []) |
|
99
|
|
|
{ |
|
100
|
|
|
return Validate::notIn($this->value, $values); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
} |