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