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

nette / forms / 20836962018

09 Jan 2026 12:35AM UTC coverage: 93.481%. Remained the same
20836962018

push

github

dg
Container::setValues() and setDefaults() accepts array|Traversable|stdClass (BC break)

3 of 4 new or added lines in 1 file covered. (75.0%)

44 existing lines in 9 files now uncovered.

2065 of 2209 relevant lines covered (93.48%)

0.93 hits per line

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

86.67
/src/Forms/Controls/SubmitButton.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 Stringable;
14
use function is_string;
15

16

17
/**
18
 * Submittable button control.
19
 *
20
 * @property-deprecated bool $submittedBy
21
 */
22
class SubmitButton extends Button implements Nette\Forms\SubmitterControl
23
{
24
        /**
25
         * Occurs when the button is clicked and form is successfully validated
26
         * @var array<callable(self, array|object): void|callable(Nette\Forms\Form, array|object): void|callable(array|object): void>
27
         */
28
        public array $onClick = [];
29

30
        /** @var array<callable(self): void>  Occurs when the button is clicked and form is not validated */
31
        public array $onInvalidClick = [];
32

33
        /** @var list<Nette\Forms\Control|Nette\Forms\Container>|null */
34
        private ?array $validationScope = null;
35

36

37
        public function __construct(string|Stringable|null $caption = null)
1✔
38
        {
39
                parent::__construct($caption);
1✔
40
                $this->control->type = 'submit';
1✔
41
        }
1✔
42

43

44
        public function loadHttpData(): void
45
        {
46
                parent::loadHttpData();
1✔
47
                if ($this->isFilled()) {
1✔
48
                        $this->getForm()->setSubmittedBy($this);
1✔
49
                }
50
        }
1✔
51

52

53
        /**
54
         * Tells if the form was submitted by this button.
55
         */
56
        public function isSubmittedBy(): bool
57
        {
58
                return $this->getForm()->isSubmitted() === $this;
1✔
59
        }
60

61

62
        /**
63
         * Sets the validation scope. Clicking the button validates only the controls within the specified scope.
64
         * @param  ?iterable<Nette\Forms\Control|Nette\Forms\Container|string>  $scope
65
         */
66
        public function setValidationScope(?iterable $scope): static
1✔
67
        {
68
                if ($scope === null) {
1✔
UNCOV
69
                        $this->validationScope = null;
×
UNCOV
70
                        return $this;
×
71
                }
72

73
                $this->validationScope = [];
1✔
74
                foreach ($scope as $control) {
1✔
75
                        if (is_string($control)) {
1✔
76
                                $control = $this->getForm()->getComponent($control);
1✔
77
                        }
78
                        if (!$control instanceof Nette\Forms\Container && !$control instanceof Nette\Forms\Control) {
1✔
UNCOV
79
                                throw new Nette\InvalidArgumentException('Validation scope accepts only Nette\Forms\Container or Nette\Forms\Control instances.');
×
80
                        }
81

82
                        $this->validationScope[] = $control;
1✔
83
                }
84
                return $this;
1✔
85
        }
86

87

88
        /**
89
         * Gets the validation scope.
90
         * @return ?array<Nette\Forms\Control|Nette\Forms\Container>
91
         */
92
        public function getValidationScope(): ?array
93
        {
94
                return $this->validationScope;
1✔
95
        }
96

97

98
        /**
99
         * Fires click event.
100
         */
101
        public function click(): void
102
        {
UNCOV
103
                Nette\Utils\Arrays::invoke($this->onClick, $this);
×
104
        }
105

106

107
        public function getControl($caption = null): Nette\Utils\Html
1✔
108
        {
109
                $scope = [];
1✔
110
                foreach ((array) $this->validationScope as $control) {
1✔
111
                        $scope[] = $control->lookupPath(Nette\Forms\Form::class);
1✔
112
                }
113

114
                return parent::getControl($caption)->addAttributes([
1✔
115
                        'formnovalidate' => $this->validationScope !== null,
1✔
116
                        'data-nette-validation-scope' => $scope ?: null,
1✔
117
                ]);
118
        }
119
}
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