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