Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • BaseControl
  • Button
  • Checkbox
  • CheckboxList
  • ChoiceControl
  • CsrfProtection
  • HiddenField
  • ImageButton
  • MultiChoiceControl
  • MultiSelectBox
  • RadioList
  • SelectBox
  • SubmitButton
  • TextArea
  • TextBase
  • TextInput
  • UploadControl
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://nette.org)
 5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\Forms\Controls;
 9: 
10: use Nette;
11: use Nette\Forms\Form;
12: 
13: 
14: /**
15:  * Single line text input control.
16:  * @property-write $type
17:  */
18: class TextInput extends TextBase
19: {
20: 
21:     /**
22:      * @param  string  label
23:      * @param  int  maximum number of characters the user may enter
24:      */
25:     public function __construct($label = NULL, $maxLength = NULL)
26:     {
27:         parent::__construct($label);
28:         $this->control->type = 'text';
29:         $this->control->maxlength = $maxLength;
30:     }
31: 
32: 
33:     /**
34:      * Loads HTTP data.
35:      * @return void
36:      */
37:     public function loadHttpData()
38:     {
39:         $this->setValue($this->getHttpData(Form::DATA_LINE));
40:     }
41: 
42: 
43:     /**
44:      * Changes control's type attribute.
45:      * @param  string
46:      * @return self
47:      */
48:     public function setType($type)
49:     {
50:         $this->control->type = $type;
51:         return $this;
52:     }
53: 
54: 
55:     /**
56:      * Generates control's HTML element.
57:      * @return Nette\Utils\Html
58:      */
59:     public function getControl()
60:     {
61:         $input = parent::getControl();
62: 
63:         foreach ($this->getRules() as $rule) {
64:             if ($rule->isNegative || $rule->branch) {
65: 
66:             } elseif (in_array($rule->validator, array(Form::MIN, Form::MAX, Form::RANGE), TRUE)
67:                 && in_array($input->type, array('number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'), TRUE)
68:             ) {
69:                 if ($rule->validator === Form::MIN) {
70:                     $range = array($rule->arg, NULL);
71:                 } elseif ($rule->validator === Form::MAX) {
72:                     $range = array(NULL, $rule->arg);
73:                 } else {
74:                     $range = $rule->arg;
75:                 }
76:                 if (isset($range[0]) && is_scalar($range[0])) {
77:                     $input->min = isset($input->min) ? max($input->min, $range[0]) : $range[0];
78:                 }
79:                 if (isset($range[1]) && is_scalar($range[1])) {
80:                     $input->max = isset($input->max) ? min($input->max, $range[1]) : $range[1];
81:                 }
82: 
83:             } elseif ($rule->validator === Form::PATTERN && is_scalar($rule->arg)
84:                 && in_array($input->type, array('text', 'search', 'tel', 'url', 'email', 'password'), TRUE)
85:             ) {
86:                 $input->pattern = $rule->arg;
87:             }
88:         }
89: 
90:         if ($input->type !== 'password' && ($this->rawValue !== '' || $this->emptyValue !== '')) {
91:             $input->value = $this->rawValue === ''
92:                 ? $this->translate($this->emptyValue)
93:                 : $this->rawValue;
94:         }
95:         return $input;
96:     }
97: 
98: }
99: 
Nette 2.3.4 API API documentation generated by ApiGen 2.8.0