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