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