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
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • 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
  • Other releases
  • Nette homepage
  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  label
 22:      * @param  int  maximum number of characters the user may enter
 23:      */
 24:     public function __construct($label = NULL, $maxLength = NULL)
 25:     {
 26:         parent::__construct($label);
 27:         $this->control->type = 'text';
 28:         $this->control->maxlength = $maxLength;
 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:         $input = parent::getControl();
 72: 
 73:         foreach ($this->getRules() as $rule) {
 74:             if ($rule->isNegative || $rule->branch) {
 75: 
 76:             } elseif (in_array($rule->validator, array(Form::MIN, Form::MAX, Form::RANGE), TRUE)
 77:                 && in_array($input->type, array('number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'), TRUE)
 78:             ) {
 79:                 if ($rule->validator === Form::MIN) {
 80:                     $range = array($rule->arg, NULL);
 81:                 } elseif ($rule->validator === Form::MAX) {
 82:                     $range = array(NULL, $rule->arg);
 83:                 } else {
 84:                     $range = $rule->arg;
 85:                 }
 86:                 if (isset($range[0]) && is_scalar($range[0])) {
 87:                     $input->min = isset($input->min) ? max($input->min, $range[0]) : $range[0];
 88:                 }
 89:                 if (isset($range[1]) && is_scalar($range[1])) {
 90:                     $input->max = isset($input->max) ? min($input->max, $range[1]) : $range[1];
 91:                 }
 92: 
 93:             } elseif ($rule->validator === Form::PATTERN && is_scalar($rule->arg)
 94:                 && in_array($input->type, array('text', 'search', 'tel', 'url', 'email', 'password'), TRUE)
 95:             ) {
 96:                 $input->pattern = $rule->arg;
 97:             }
 98:         }
 99: 
100:         if ($input->type !== 'password' && ($this->rawValue !== '' || $this->emptyValue !== '')) {
101:             $input->value = $this->rawValue === ''
102:                 ? $this->translate($this->emptyValue)
103:                 : $this->rawValue;
104:         }
105:         return $input;
106:     }
107: 
108: }
109: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0