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:
20: class TextInput extends TextBase
21: {
22:
23: 24: 25: 26:
27: public function __construct($label = NULL, $maxLength = NULL)
28: {
29: parent::__construct($label);
30: $this->control->type = 'text';
31: $this->control->maxlength = $maxLength;
32: }
33:
34:
35: 36: 37: 38:
39: public function loadHttpData()
40: {
41: $this->setValue($this->getHttpData(Form::DATA_LINE));
42: }
43:
44:
45: 46: 47: 48: 49:
50: public function setType($type)
51: {
52: $this->control->type = $type;
53: return $this;
54: }
55:
56:
57: 58: 59: 60:
61: public function getControl()
62: {
63: $input = parent::getControl();
64:
65: foreach ($this->getRules() as $rule) {
66: if ($rule->isNegative || $rule->branch) {
67:
68: } elseif (in_array($rule->validator, array(Form::MIN, Form::MAX, Form::RANGE), TRUE)
69: && in_array($input->type, array('number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'), TRUE)
70: ) {
71: if ($rule->validator === Form::MIN) {
72: $range = array($rule->arg, NULL);
73: } elseif ($rule->validator === Form::MAX) {
74: $range = array(NULL, $rule->arg);
75: } else {
76: $range = $rule->arg;
77: }
78: if (isset($range[0]) && is_scalar($range[0])) {
79: $input->min = isset($input->min) ? max($input->min, $range[0]) : $range[0];
80: }
81: if (isset($range[1]) && is_scalar($range[1])) {
82: $input->max = isset($input->max) ? min($input->max, $range[1]) : $range[1];
83: }
84:
85: } elseif ($rule->validator === Form::PATTERN && is_scalar($rule->arg)
86: && in_array($input->type, array('text', 'search', 'tel', 'url', 'email', 'password'), TRUE)
87: ) {
88: $input->pattern = $rule->arg;
89: }
90: }
91:
92: if ($input->type !== 'password' && ($this->rawValue !== '' || $this->emptyValue !== '')) {
93: $input->value = $this->rawValue === ''
94: ? $this->translate($this->emptyValue)
95: : $this->rawValue;
96: }
97: return $input;
98: }
99:
100: }
101: