|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Form\Widget\Attribute; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Html\Html; |
|
8
|
|
|
use Yiisoft\Widget\Widget; |
|
9
|
|
|
|
|
10
|
|
|
abstract class ButtonAttributes extends Widget |
|
11
|
|
|
{ |
|
12
|
|
|
use GlobalAttributes; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Set whether the element is disabled or not. |
|
16
|
|
|
* |
|
17
|
|
|
* If this attribute is set to `true`, the element is disabled. Disabled elements are usually drawn with grayed-out |
|
18
|
|
|
* text. |
|
19
|
|
|
* If the element is disabled, it does not respond to user actions, it cannot be focused, and the command event |
|
20
|
|
|
* will not fire. In the case of form elements, it will not be submitted. Do not set the attribute to true, as |
|
21
|
|
|
* this will suggest you can set it to `false` to enable the element again, which is not the case. |
|
22
|
|
|
* |
|
23
|
|
|
* @return static |
|
24
|
|
|
* |
|
25
|
|
|
* @link https://www.w3.org/TR/html52/sec-forms.html#element-attrdef-disabledformelements-disabled |
|
26
|
|
|
*/ |
|
27
|
|
|
public function disabled(): self |
|
28
|
|
|
{ |
|
29
|
|
|
$new = clone $this; |
|
30
|
|
|
$new->attributes['disabled'] = true; |
|
31
|
|
|
return $new; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Specifies the form element the tag input element belongs to. The value of this attribute must be the id |
|
36
|
|
|
* attribute of a {@see Form} element in the same document. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $value |
|
39
|
|
|
* |
|
40
|
|
|
* @return static |
|
41
|
|
|
* |
|
42
|
|
|
* @link https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form |
|
43
|
|
|
*/ |
|
44
|
|
|
public function form(string $value): self |
|
45
|
|
|
{ |
|
46
|
|
|
$new = clone $this; |
|
47
|
|
|
$new->attributes['form'] = $value; |
|
48
|
|
|
return $new; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Set build attributes for the widget. |
|
53
|
|
|
* |
|
54
|
|
|
* @param array $attributes $value |
|
55
|
|
|
* @param string $suffix The suffix of the attribute name. |
|
56
|
|
|
* |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function build(array $attributes, string $suffix): array |
|
60
|
|
|
{ |
|
61
|
|
|
$id = Html::generateId('w') . $suffix; |
|
62
|
|
|
|
|
63
|
|
|
if (!array_key_exists('id', $attributes)) { |
|
64
|
|
|
$attributes['id'] = $id; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (!array_key_exists('name', $attributes)) { |
|
68
|
|
|
$attributes['name'] = $id; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $attributes; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|