• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / forms / 19788540141

29 Nov 2025 07:50PM UTC coverage: 92.968% (-0.06%) from 93.023%
19788540141

Pull #347

github

web-flow
Merge aa0ec7ff1 into 0e1918f18
Pull Request #347: Allow to delegate rule validation to (Validated)Control

12 of 14 new or added lines in 2 files covered. (85.71%)

55 existing lines in 9 files now uncovered.

2089 of 2247 relevant lines covered (92.97%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/src/Forms/Controls/Checkbox.php
1
<?php
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Nette\Forms\Controls;
11

12
use Nette;
13
use Nette\Utils\Html;
14
use Stringable;
15
use function is_scalar, sprintf;
16

17

18
/**
19
 * Check box control. Allows the user to select a true or false condition.
20
 */
21
class Checkbox extends BaseControl
22
{
23
        private Html $container;
24

25

26
        public function __construct(string|Stringable|null $label = null)
1✔
27
        {
28
                parent::__construct($label);
1✔
29
                $this->control->type = 'checkbox';
1✔
30
                $this->container = Html::el();
1✔
31
                $this->setOption('type', 'checkbox');
1✔
32
        }
1✔
33

34

35
        /**
36
         * Sets control's value.
37
         * @internal
38
         */
39
        public function setValue($value): static
40
        {
41
                if (!is_scalar($value) && $value !== null) {
1✔
42
                        throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or null, %s given in field '%s'.", get_debug_type($value), $this->getName()));
1✔
43
                }
44

45
                $this->value = (bool) $value;
1✔
46
                return $this;
1✔
47
        }
48

49

50
        public function isFilled(): bool
51
        {
52
                return $this->getValue() !== false; // back compatibility
1✔
53
        }
54

55

56
        public function getControl(): Html
57
        {
58
                return $this->container->setHtml($this->getLabelPart()->insert(0, $this->getControlPart()));
1✔
59
        }
60

61

62
        /**
63
         * Bypasses label generation.
64
         */
65
        public function getLabel($caption = null): Html|string|null
1✔
66
        {
67
                return null;
1✔
68
        }
69

70

71
        public function getControlPart(): Html
72
        {
73
                return parent::getControl()->checked($this->value);
1✔
74
        }
75

76

77
        public function getLabelPart(): Html
78
        {
79
                return parent::getLabel();
1✔
80
        }
81

82

83
        /**
84
         * Returns container HTML element template.
85
         */
86
        public function getContainerPrototype(): Html
87
        {
UNCOV
88
                return $this->container;
×
89
        }
90

91

92
        #[\Deprecated('use getContainerPrototype()')]
93
        public function getSeparatorPrototype(): Html
94
        {
95
                trigger_error(__METHOD__ . '() was renamed to getContainerPrototype()', E_USER_DEPRECATED);
×
UNCOV
96
                return $this->container;
×
97
        }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc