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