1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Forms\Controls;
9:
10: use Nette;
11:
12:
13: 14: 15: 16: 17: 18:
19: class TextInput extends TextBase
20: {
21:
22: 23: 24: 25:
26: public function __construct($label = NULL, $maxLength = NULL)
27: {
28: parent::__construct($label);
29: $this->control->type = 'text';
30: $this->control->maxlength = $maxLength;
31: }
32:
33:
34: 35: 36: 37:
38: public function loadHttpData()
39: {
40: $this->setValue($this->getHttpData(Nette\Forms\Form::DATA_LINE));
41: }
42:
43:
44: 45: 46: 47: 48:
49: public function setType($type)
50: {
51: $this->control->type = $type;
52: return $this;
53: }
54:
55:
56:
57: public function setPasswordMode($mode = TRUE)
58: {
59: trigger_error(__METHOD__ . '() is deprecated; use setType("password") instead.', E_USER_DEPRECATED);
60: $this->control->type = $mode ? 'password' : 'text';
61: return $this;
62: }
63:
64:
65: 66: 67: 68:
69: public function getControl()
70: {
71: $input = parent::getControl();
72:
73: foreach ($this->getRules() as $rule) {
74: if ($rule->isNegative || $rule->type !== Nette\Forms\Rule::VALIDATOR) {
75:
76: } elseif ($rule->operation === Nette\Forms\Form::RANGE
77: && in_array($input->type, array('number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'), TRUE)
78: ) {
79: if (isset($rule->arg[0]) && is_scalar($rule->arg[0])) {
80: $input->min = isset($input->min) ? max($input->min, $rule->arg[0]) : $rule->arg[0];
81: }
82: if (isset($rule->arg[1]) && is_scalar($rule->arg[1])) {
83: $input->max = isset($input->max) ? min($input->max, $rule->arg[1]) : $rule->arg[1];
84: }
85:
86: } elseif ($rule->operation === Nette\Forms\Form::PATTERN && is_scalar($rule->arg)
87: && in_array($input->type, array('text', 'search', 'tel', 'url', 'email', 'password'), TRUE)
88: ) {
89: $input->pattern = $rule->arg;
90: }
91: }
92:
93: if ($input->type !== 'password') {
94: $input->value = $this->rawValue === '' ? $this->translate($this->emptyValue) : $this->rawValue;
95: }
96: return $input;
97: }
98:
99: }
100: