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

nette / forms / 26452888331

26 May 2026 02:01PM UTC coverage: 93.307% (+0.07%) from 93.241%
26452888331

push

github

dg
added CLAUDE.md

2105 of 2256 relevant lines covered (93.31%)

0.93 hits per line

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

97.56
/src/Forms/Controls/TextInput.php
1
<?php declare(strict_types=1);
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
namespace Nette\Forms\Controls;
9

10
use Nette;
11
use Nette\Forms\Form;
12
use Stringable;
13
use function in_array, is_scalar, max, min;
14

15

16
/**
17
 * Single line text input control.
18
 */
19
class TextInput extends TextBase
20
{
21
        public function __construct(string|Stringable|null $label = null, ?int $maxLength = null)
1✔
22
        {
23
                parent::__construct($label);
1✔
24
                $this->control->maxlength = $maxLength;
1✔
25
                $this->setOption('type', 'text');
1✔
26
        }
1✔
27

28

29
        public function loadHttpData(): void
30
        {
31
                $this->setValue($this->getHttpData(Form::DataLine));
1✔
32
        }
1✔
33

34

35
        /**
36
         * Changes control's type attribute.
37
         */
38
        public function setHtmlType(string $type): static
1✔
39
        {
40
                $this->control->type = $type;
1✔
41
                return $this;
1✔
42
        }
43

44

45
        /**
46
         * @deprecated  use setHtmlType()
47
         */
48
        public function setType(string $type): static
49
        {
50
                return $this->setHtmlType($type);
×
51
        }
52

53

54
        public function getControl(): Nette\Utils\Html
55
        {
56
                return parent::getControl()->addAttributes([
1✔
57
                        'value' => $this->control->type === 'password' ? $this->control->value : $this->getRenderedValue(),
1✔
58
                        'type' => $this->control->type ?? 'text',
1✔
59
                ]);
60
        }
61

62

63
        /**
64
         * @param  (callable(Nette\Forms\Control): bool)|string  $validator
65
         * @return static
66
         */
67
        public function addRule(
1✔
68
                callable|string $validator,
69
                string|Stringable|null $errorMessage = null,
70
                mixed $arg = null,
71
        ) {
72
                foreach ($this->getRules() as $rule) {
1✔
73
                        if (!$rule->canExport() && !$rule->branch) {
1✔
74
                                return parent::addRule($validator, $errorMessage, $arg);
1✔
75
                        }
76
                }
77

78
                if ($this->control->type === null && in_array($validator, [Form::Email, Form::URL, Form::Integer], strict: true)) {
1✔
79
                        $types = [Form::Email => 'email', Form::URL => 'url', Form::Integer => 'number'];
1✔
80
                        $this->control->type = $types[$validator];
1✔
81

82
                } elseif (
83
                        in_array($validator, [Form::Min, Form::Max, Form::Range], strict: true)
1✔
84
                        && in_array($this->control->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], strict: true)
1✔
85
                ) {
86
                        if ($validator === Form::Min) {
1✔
87
                                $range = [$arg, null];
1✔
88
                        } elseif ($validator === Form::Max) {
1✔
89
                                $range = [null, $arg];
1✔
90
                        } else {
91
                                $range = $arg;
1✔
92
                        }
93

94
                        if (isset($range[0]) && is_scalar($range[0])) {
1✔
95
                                $this->control->min = isset($this->control->min)
1✔
96
                                        ? max($this->control->min, $range[0])
1✔
97
                                        : $range[0];
1✔
98
                        }
99

100
                        if (isset($range[1]) && is_scalar($range[1])) {
1✔
101
                                $this->control->max = isset($this->control->max)
1✔
102
                                        ? min($this->control->max, $range[1])
1✔
103
                                        : $range[1];
1✔
104
                        }
105

106
                } elseif (
107
                        $validator === Form::Pattern
1✔
108
                        && is_scalar($arg)
1✔
109
                        && in_array($this->control->type, [null, 'text', 'search', 'tel', 'url', 'email', 'password'], strict: true)
1✔
110
                ) {
111
                        $this->control->pattern = (string) $arg;
1✔
112
                }
113

114
                return parent::addRule($validator, $errorMessage, $arg);
1✔
115
        }
116
}
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