1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: * @package Nette\Forms\Controls
11: */
12:
13:
14:
15: /**
16: * Single line text input control.
17: *
18: * @author David Grudl
19: * @property-write $type
20: * @package Nette\Forms\Controls
21: */
22: class NTextInput extends NTextBase
23: {
24:
25: /**
26: * @param string label
27: * @param int width of the control
28: * @param int maximum number of characters the user may enter
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: }
37:
38:
39: /**
40: * Changes control's type attribute.
41: * @param string
42: * @return self
43: */
44: public function setType($type)
45: {
46: $this->control->type = $type;
47: return $this;
48: }
49:
50:
51: /** @deprecated */
52: public function setPasswordMode($mode = TRUE)
53: {
54: $this->control->type = $mode ? 'password' : 'text';
55: return $this;
56: }
57:
58:
59: /**
60: * Generates control's HTML element.
61: * @return NHtml
62: */
63: public function getControl()
64: {
65: $control = parent::getControl();
66: foreach ($this->getRules() as $rule) {
67: if ($rule->isNegative || $rule->type !== NRule::VALIDATOR) {
68:
69: } elseif ($rule->operation === NForm::RANGE && $control->type !== 'text') {
70: list($control->min, $control->max) = $rule->arg;
71:
72: } elseif ($rule->operation === NForm::PATTERN) {
73: $control->pattern = $rule->arg;
74: }
75: }
76: if ($control->type !== 'password') {
77: $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value;
78: }
79: return $control;
80: }
81:
82: }
83: