|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Form\Widget; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Form\FormModelInterface; |
|
8
|
|
|
use Yiisoft\Widget\Widget; |
|
9
|
|
|
|
|
10
|
|
|
final class DatePicker extends Widget |
|
11
|
|
|
{ |
|
12
|
|
|
private FormModelInterface $data; |
|
13
|
|
|
private string $attribute; |
|
14
|
|
|
private array $options = []; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Generates a datepicker tag together with a label for the given form attribute. |
|
18
|
|
|
* |
|
19
|
|
|
* @return string the generated checkbox tag. |
|
20
|
|
|
*/ |
|
21
|
8 |
|
public function run(): string |
|
22
|
|
|
{ |
|
23
|
8 |
|
return Input::widget() |
|
24
|
8 |
|
->type('date') |
|
|
|
|
|
|
25
|
8 |
|
->config($this->data, $this->attribute, $this->options) |
|
26
|
8 |
|
->run(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Set form model, name and options for the widget. |
|
31
|
|
|
* |
|
32
|
|
|
* @param FormModelInterface $data Form model. |
|
33
|
|
|
* @param string $attribute Form model property this widget is rendered for. |
|
34
|
|
|
* @param array $options The HTML attributes for the widget container tag. |
|
35
|
|
|
* See {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered. |
|
36
|
|
|
* |
|
37
|
|
|
* @return self |
|
38
|
|
|
*/ |
|
39
|
8 |
|
public function config(FormModelInterface $data, string $attribute, array $options = []): self |
|
40
|
|
|
{ |
|
41
|
8 |
|
$new = clone $this; |
|
42
|
8 |
|
$new->data = $data; |
|
43
|
8 |
|
$new->attribute = $attribute; |
|
44
|
8 |
|
$new->options = $options; |
|
45
|
8 |
|
return $new; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Focus on the control (put cursor into it) when the page loads. |
|
50
|
|
|
* Only one form element could be in focus at the same time. |
|
51
|
|
|
* |
|
52
|
|
|
* @param bool $value |
|
53
|
|
|
* |
|
54
|
|
|
* @return self |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public function autofocus(bool $value = true): self |
|
57
|
|
|
{ |
|
58
|
1 |
|
$new = clone $this; |
|
59
|
1 |
|
$new->options['autofocus'] = $value; |
|
60
|
1 |
|
return $new; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Set whether the element is disabled or not. |
|
65
|
|
|
* |
|
66
|
|
|
* If this attribute is set to `true`, the element is disabled. Disabled elements are usually drawn with grayed-out |
|
67
|
|
|
* text. |
|
68
|
|
|
* If the element is disabled, it does not respond to user actions, it cannot be focused, and the command event |
|
69
|
|
|
* will not fire. In the case of form elements, it will not be submitted. Do not set the attribute to true, as |
|
70
|
|
|
* this will suggest you can set it to false to enable the element again, which is not the case. |
|
71
|
|
|
* |
|
72
|
|
|
* @param bool $value |
|
73
|
|
|
* |
|
74
|
|
|
* @return self |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function disabled(bool $value = true): self |
|
77
|
|
|
{ |
|
78
|
1 |
|
$new = clone $this; |
|
79
|
1 |
|
$new->options['disabled'] = $value; |
|
80
|
1 |
|
return $new; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* The earliest acceptable date. |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $value |
|
87
|
|
|
* |
|
88
|
|
|
* @return self |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function min(string $value): self |
|
91
|
|
|
{ |
|
92
|
1 |
|
$new = clone $this; |
|
93
|
1 |
|
$new->options['min'] = $value; |
|
94
|
1 |
|
return $new; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* The latest acceptable date. |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $value |
|
101
|
|
|
* |
|
102
|
|
|
* @return self |
|
103
|
|
|
*/ |
|
104
|
1 |
|
public function max(string $value): self |
|
105
|
|
|
{ |
|
106
|
1 |
|
$new = clone $this; |
|
107
|
1 |
|
$new->options['max'] = $value; |
|
108
|
1 |
|
return $new; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* If it is required to fill in a value in order to submit the form. |
|
113
|
|
|
* |
|
114
|
|
|
* @param bool $value |
|
115
|
|
|
* |
|
116
|
|
|
* @return self |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function required(bool $value = true): self |
|
119
|
|
|
{ |
|
120
|
1 |
|
$new = clone $this; |
|
121
|
1 |
|
$new->options['required'] = $value; |
|
122
|
1 |
|
return $new; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* The tabindex global attribute indicates that its element can be focused, and where it participates in sequential |
|
127
|
|
|
* keyboard navigation (usually with the Tab key, hence the name). |
|
128
|
|
|
* |
|
129
|
|
|
* It accepts an integer as a value, with different results depending on the integer's value: |
|
130
|
|
|
* |
|
131
|
|
|
* - A negative value (usually tabindex="-1") means that the element is not reachable via sequential keyboard |
|
132
|
|
|
* navigation, but could be focused with Javascript or visually. It's mostly useful to create accessible widgets |
|
133
|
|
|
* with JavaScript. |
|
134
|
|
|
* - tabindex="0" means that the element should be focusable in sequential keyboard navigation, but its order is |
|
135
|
|
|
* defined by the document's source order. |
|
136
|
|
|
* - A positive value means the element should be focusable in sequential keyboard navigation, with its order |
|
137
|
|
|
* defined by the value of the number. That is, tabindex="4" is focused before tabindex="5", but after tabindex="3". |
|
138
|
|
|
* |
|
139
|
|
|
* @param int $value |
|
140
|
|
|
* |
|
141
|
|
|
* @return self |
|
142
|
|
|
*/ |
|
143
|
1 |
|
public function tabIndex(int $value = 0): self |
|
144
|
|
|
{ |
|
145
|
1 |
|
$new = clone $this; |
|
146
|
1 |
|
$new->options['tabindex'] = $value; |
|
147
|
1 |
|
return $new; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|