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