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 && iconv_strlen($value, 'UTF-8') > $this->control->maxlength) {
49: $value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
50: }
51: return NString::trim(strtr($value, "\r\n", ' '));
52: }
53:
54:
55:
56: 57: 58: 59: 60:
61: public function setPasswordMode($mode = TRUE)
62: {
63: $this->control->type = $mode ? 'password' : 'text';
64: return $this;
65: }
66:
67:
68:
69: 70: 71: 72:
73: public function getControl()
74: {
75: $control = parent::getControl();
76: if ($this->control->type !== 'password') {
77: $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value;
78: }
79: return $control;
80: }
81:
82:
83:
84: public function notifyRule(NRule $rule)
85: {
86: if (is_string($rule->operation) && strcasecmp($rule->operation, ':length') === 0 && !$rule->isNegative) {
87: $this->control->maxlength = is_array($rule->arg) ? $rule->arg[1] : $rule->arg;
88:
89: } elseif (is_string($rule->operation) && strcasecmp($rule->operation, ':maxLength') === 0 && !$rule->isNegative) {
90: $this->control->maxlength = $rule->arg;
91: }
92:
93: parent::notifyRule($rule);
94: }
95:
96:
97: }
98: