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
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

  • BaseControl
  • Button
  • Checkbox
  • CheckboxList
  • ChoiceControl
  • CsrfProtection
  • HiddenField
  • ImageButton
  • MultiChoiceControl
  • MultiSelectBox
  • RadioList
  • SelectBox
  • SubmitButton
  • TextArea
  • TextBase
  • TextInput
  • UploadControl
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (https://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:  */
 17: class TextInput extends TextBase
 18: {
 19: 
 20:     /**
 21:      * @param  string|object
 22:      * @param  int
 23:      */
 24:     public function __construct($label = null, $maxLength = null)
 25:     {
 26:         parent::__construct($label);
 27:         $this->control->maxlength = $maxLength;
 28:         $this->setOption('type', 'text');
 29:     }
 30: 
 31: 
 32:     /**
 33:      * Loads HTTP data.
 34:      * @return void
 35:      */
 36:     public function loadHttpData()
 37:     {
 38:         $this->setValue($this->getHttpData(Form::DATA_LINE));
 39:     }
 40: 
 41: 
 42:     /**
 43:      * Changes control's type attribute.
 44:      * @param  string
 45:      * @return static
 46:      */
 47:     public function setHtmlType($type)
 48:     {
 49:         return $this->setType($type);
 50:     }
 51: 
 52: 
 53:     /**
 54:      * Alias for setHtmlType()
 55:      * @param  string
 56:      * @return static
 57:      */
 58:     public function setType($type)
 59:     {
 60:         $this->control->type = $type;
 61:         return $this;
 62:     }
 63: 
 64: 
 65:     /**
 66:      * Generates control's HTML element.
 67:      * @return Nette\Utils\Html
 68:      */
 69:     public function getControl()
 70:     {
 71:         return parent::getControl()->addAttributes([
 72:             'value' => $this->control->type === 'password' ? $this->control->value : $this->getRenderedValue(),
 73:             'type' => $this->control->type ?: 'text',
 74:         ]);
 75:     }
 76: 
 77: 
 78:     /**
 79:      * @return static
 80:      */
 81:     public function addRule($validator, $errorMessage = null, $arg = null)
 82:     {
 83:         if ($this->control->type === null && in_array($validator, [Form::EMAIL, Form::URL, Form::INTEGER], true)) {
 84:             static $types = [Form::EMAIL => 'email', Form::URL => 'url', Form::INTEGER => 'number'];
 85:             $this->control->type = $types[$validator];
 86: 
 87:         } elseif (
 88:             in_array($validator, [Form::MIN, Form::MAX, Form::RANGE], true)
 89:             && in_array($this->control->type, ['number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'], true)
 90:         ) {
 91:             if ($validator === Form::MIN) {
 92:                 $range = [$arg, null];
 93:             } elseif ($validator === Form::MAX) {
 94:                 $range = [null, $arg];
 95:             } else {
 96:                 $range = $arg;
 97:             }
 98:             if (isset($range[0]) && is_scalar($range[0])) {
 99:                 $this->control->min = isset($this->control->min) ? max($this->control->min, $range[0]) : $range[0];
100:             }
101:             if (isset($range[1]) && is_scalar($range[1])) {
102:                 $this->control->max = isset($this->control->max) ? min($this->control->max, $range[1]) : $range[1];
103:             }
104: 
105:         } elseif (
106:             $validator === Form::PATTERN
107:             && is_scalar($arg)
108:             && in_array($this->control->type, [null, 'text', 'search', 'tel', 'url', 'email', 'password'], true)
109:         ) {
110:             $this->control->pattern = $arg;
111:         }
112: 
113:         return parent::addRule($validator, $errorMessage, $arg);
114:     }
115: }
116: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0