1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Forms\Controls;
9:
10: use Nette;
11: use Nette\Forms\Form;
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(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: 58: 59:
60: public function getControl()
61: {
62: $input = parent::getControl();
63:
64: foreach ($this->getRules() as $rule) {
65: if ($rule->isNegative || $rule->branch) {
66:
67: } elseif (in_array($rule->validator, array(Form::MIN, Form::MAX, Form::RANGE), TRUE)
68: && in_array($input->type, array('number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'), TRUE)
69: ) {
70: if ($rule->validator === Form::MIN) {
71: $range = array($rule->arg, NULL);
72: } elseif ($rule->validator === Form::MAX) {
73: $range = array(NULL, $rule->arg);
74: } else {
75: $range = $rule->arg;
76: }
77: if (isset($range[0]) && is_scalar($range[0])) {
78: $input->min = isset($input->min) ? max($input->min, $range[0]) : $range[0];
79: }
80: if (isset($range[1]) && is_scalar($range[1])) {
81: $input->max = isset($input->max) ? min($input->max, $range[1]) : $range[1];
82: }
83:
84: } elseif ($rule->validator === Form::PATTERN && is_scalar($rule->arg)
85: && in_array($input->type, array('text', 'search', 'tel', 'url', 'email', 'password'), TRUE)
86: ) {
87: $input->pattern = $rule->arg;
88: }
89: }
90:
91: if ($input->type !== 'password' && ($this->rawValue !== '' || $this->emptyValue !== '')) {
92: $input->value = $this->rawValue === ''
93: ? $this->translate($this->emptyValue)
94: : $this->rawValue;
95: }
96: return $input;
97: }
98:
99: }
100: