|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2020 Enjoys. |
|
7
|
|
|
* |
|
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
10
|
|
|
* in the Software without restriction, including without limitation the rights |
|
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
13
|
|
|
* furnished to do so, subject to the following conditions: |
|
14
|
|
|
* |
|
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
16
|
|
|
* all copies or substantial portions of the Software. |
|
17
|
|
|
* |
|
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
24
|
|
|
* THE SOFTWARE. |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
declare(strict_types=1); |
|
28
|
|
|
|
|
29
|
|
|
namespace Enjoys\Forms\Elements; |
|
30
|
|
|
|
|
31
|
|
|
use Enjoys\Forms\Element; |
|
32
|
|
|
use Enjoys\Forms\Traits\Description; |
|
33
|
|
|
use Enjoys\Forms\Traits\Rules; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Description of Textarea |
|
37
|
|
|
* |
|
38
|
|
|
* @author Enjoys |
|
39
|
|
|
*/ |
|
40
|
|
|
class Textarea extends Element |
|
41
|
|
|
{ |
|
42
|
|
|
use Description; |
|
43
|
|
|
use Rules; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected string $type = 'textarea'; |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
private string $value; |
|
53
|
|
|
|
|
54
|
|
|
public function __construct(string $name, string $label = null) |
|
55
|
|
|
{ |
|
56
|
|
|
parent::__construct($name, $label); |
|
57
|
|
|
$this->value = ''; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function setValue(string $value): self |
|
61
|
|
|
{ |
|
62
|
|
|
$this->value = $value; |
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getValue(): string |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->value; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* rows Высота поля в строках текста. |
|
73
|
|
|
* @param string|int $rows |
|
74
|
|
|
* @return $this |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setRows($rows): self |
|
77
|
|
|
{ |
|
78
|
|
|
$this->setAttribute('rows', (string) $rows); |
|
79
|
|
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* cols Ширина поля в символах. |
|
84
|
|
|
* @param string|int $cols |
|
85
|
|
|
* @return $this |
|
86
|
|
|
*/ |
|
87
|
|
|
public function setCols($cols): self |
|
88
|
|
|
{ |
|
89
|
|
|
$this->setAttribute('cols', (string) $cols); |
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function baseHtml(): string |
|
94
|
|
|
{ |
|
95
|
|
|
$value = $this->getAttribute('value'); |
|
96
|
|
|
if ($value !== false) { |
|
97
|
|
|
$this->setValue($value); |
|
98
|
|
|
$this->removeAttribute('value'); |
|
99
|
|
|
} |
|
100
|
|
|
return "<textarea{$this->getAttributesString()}>{$this->getValue()}</textarea>"; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|