1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Nette\Forms\Controls;
13:
14: use Nette;
15:
16:
17:
18: 19: 20: 21: 22: 23:
24: class TextInput extends TextBase
25: {
26:
27: 28: 29: 30: 31: 32:
33: public function __construct($label = NULL, $cols = NULL, $maxLength = NULL)
34: {
35: parent::__construct($label);
36: $this->control->type = 'text';
37: $this->control->size = $cols;
38: $this->control->maxlength = $maxLength;
39: $this->addFilter($this->sanitize);
40: $this->value = '';
41: }
42:
43:
44:
45: 46: 47: 48:
49: public function sanitize($value)
50: {
51: if ($this->control->maxlength && Nette\Utils\Strings::length($value) > $this->control->maxlength) {
52: $value = Nette\Utils\Strings::substring($value, 0, $this->control->maxlength);
53: }
54: return Nette\Utils\Strings::trim(strtr($value, "\r\n", ' '));
55: }
56:
57:
58:
59: 60: 61: 62: 63:
64: public function setType($type)
65: {
66: $this->control->type = $type;
67: return $this;
68: }
69:
70:
71:
72:
73: public function setPasswordMode($mode = TRUE)
74: {
75: $this->control->type = $mode ? 'password' : 'text';
76: return $this;
77: }
78:
79:
80:
81: 82: 83: 84:
85: public function getControl()
86: {
87: $control = parent::getControl();
88: foreach ($this->getRules() as $rule) {
89: if ($rule->isNegative || $rule->type !== Nette\Forms\Rule::VALIDATOR) {
90:
91: } elseif ($rule->operation === Nette\Forms\Form::RANGE && $control->type !== 'text') {
92: list($control->min, $control->max) = $rule->arg;
93:
94: } elseif ($rule->operation === Nette\Forms\Form::PATTERN) {
95: $control->pattern = $rule->arg;
96: }
97: }
98: if ($control->type !== 'password') {
99: $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value;
100: }
101: return $control;
102: }
103:
104: }
105: