-
-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathCheckbox.php
More file actions
97 lines (75 loc) · 1.69 KB
/
Checkbox.php
File metadata and controls
97 lines (75 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Forms\Controls;
use Nette;
use Nette\Utils\Html;
/**
* Check box control. Allows the user to select a true or false condition.
*/
class Checkbox extends BaseControl
{
/** @var Html wrapper element template */
private $wrapper;
/**
* @param string|object
*/
public function __construct($label = null)
{
parent::__construct($label);
$this->control->type = 'checkbox';
$this->wrapper = Html::el();
$this->setOption('type', 'checkbox');
}
/**
* Sets control's value.
* @return static
* @internal
*/
public function setCurrentValue($value)
{
if (!is_scalar($value) && $value !== null) {
throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or null, %s given in field '%s'.", gettype($value), $this->name));
}
$this->value = (bool) $value;
return $this;
}
/**
* Is control filled?
*/
public function isFilled(): bool
{
return $this->getValue() !== false; // back compatibility
}
/**
* Generates control's HTML element.
*/
public function getControl(): Html
{
return $this->wrapper->setHtml($this->getLabelPart()->insert(0, $this->getControlPart()));
}
/**
* Bypasses label generation.
*/
public function getLabel($caption = null): void
{
}
public function getControlPart(): Html
{
return parent::getControl()->checked($this->value);
}
public function getLabelPart(): Html
{
return parent::getLabel();
}
/**
* Returns wrapper HTML element template.
*/
public function getSeparatorPrototype(): Html
{
return $this->wrapper;
}
}