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