1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Form\Field\Base; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use ReflectionClass; |
9
|
|
|
use Yiisoft\Html\Html; |
10
|
|
|
|
11
|
|
|
use function is_string; |
12
|
|
|
|
13
|
|
|
abstract class AbstractDateTimeField extends AbstractInputField |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @link https://html.spec.whatwg.org/multipage/input.html#attr-input-max |
17
|
|
|
*/ |
18
|
1 |
|
final public function max(?string $value): static |
19
|
|
|
{ |
20
|
1 |
|
$new = clone $this; |
21
|
1 |
|
$new->inputTagAttributes['max'] = $value; |
22
|
1 |
|
return $new; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @link https://html.spec.whatwg.org/multipage/input.html#attr-input-min |
27
|
|
|
*/ |
28
|
1 |
|
final public function min(?string $value): static |
29
|
|
|
{ |
30
|
1 |
|
$new = clone $this; |
31
|
1 |
|
$new->inputTagAttributes['min'] = $value; |
32
|
1 |
|
return $new; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* A boolean attribute that controls whether or not the user can edit the form control. |
37
|
|
|
* |
38
|
|
|
* @param bool $value Whether to allow the value to be edited by the user. |
39
|
|
|
* |
40
|
|
|
* @link https://html.spec.whatwg.org/multipage/input.html#attr-input-readonly |
41
|
|
|
*/ |
42
|
|
|
final public function readonly(bool $value = true): static |
43
|
|
|
{ |
44
|
|
|
$new = clone $this; |
45
|
|
|
$new->inputTagAttributes['readonly'] = $value; |
46
|
|
|
return $new; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* A boolean attribute. When specified, the element is required. |
51
|
|
|
* |
52
|
|
|
* @param bool $value Whether the control is required for form submission. |
53
|
|
|
* |
54
|
|
|
* @link https://html.spec.whatwg.org/multipage/input.html#attr-input-required |
55
|
|
|
*/ |
56
|
|
|
final public function required(bool $value = true): static |
57
|
|
|
{ |
58
|
|
|
$new = clone $this; |
59
|
|
|
$new->inputTagAttributes['required'] = $value; |
60
|
|
|
return $new; |
61
|
|
|
} |
62
|
|
|
|
63
|
5 |
|
final protected function generateInput(): string |
64
|
|
|
{ |
65
|
5 |
|
$value = $this->getAttributeValue(); |
66
|
|
|
|
67
|
5 |
|
if (!is_string($value) && $value !== null) { |
68
|
|
|
throw new InvalidArgumentException( |
69
|
|
|
(new ReflectionClass($this))->getShortName() . |
70
|
|
|
' widget must be a string or null value.' |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
5 |
|
$tagAttributes = $this->getInputTagAttributes(); |
75
|
|
|
|
76
|
5 |
|
return Html::input($this->getInputType(), $this->getInputName(), $value, $tagAttributes)->render(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
abstract protected function getInputType(): string; |
80
|
|
|
} |
81
|
|
|
|