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