Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationLatte
      • ApplicationTracy
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsLatte
      • Framework
      • HttpTracy
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • 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

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:  * @author     David Grudl
 18:  */
 19: class TextInput extends TextBase
 20: {
 21: 
 22:     /**
 23:      * @param  string  label
 24:      * @param  int  maximum number of characters the user may enter
 25:      */
 26:     public function __construct($label = NULL, $maxLength = NULL)
 27:     {
 28:         parent::__construct($label);
 29:         $this->control->type = 'text';
 30:         $this->control->maxlength = $maxLength;
 31:     }
 32: 
 33: 
 34:     /**
 35:      * Loads HTTP data.
 36:      * @return void
 37:      */
 38:     public function loadHttpData()
 39:     {
 40:         $this->setValue($this->getHttpData(Form::DATA_LINE));
 41:     }
 42: 
 43: 
 44:     /**
 45:      * Changes control's type attribute.
 46:      * @param  string
 47:      * @return self
 48:      */
 49:     public function setType($type)
 50:     {
 51:         $this->control->type = $type;
 52:         return $this;
 53:     }
 54: 
 55: 
 56:     /**
 57:      * Generates control's HTML element.
 58:      * @return Nette\Utils\Html
 59:      */
 60:     public function getControl()
 61:     {
 62:         $input = parent::getControl();
 63: 
 64:         foreach ($this->getRules() as $rule) {
 65:             if ($rule->isNegative || $rule->branch) {
 66: 
 67:             } elseif (in_array($rule->validator, array(Form::MIN, Form::MAX, Form::RANGE), TRUE)
 68:                 && in_array($input->type, array('number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'), TRUE)
 69:             ) {
 70:                 if ($rule->validator === Form::MIN) {
 71:                     $range = array($rule->arg, NULL);
 72:                 } elseif ($rule->validator === Form::MAX) {
 73:                     $range = array(NULL, $rule->arg);
 74:                 } else {
 75:                     $range = $rule->arg;
 76:                 }
 77:                 if (isset($range[0]) && is_scalar($range[0])) {
 78:                     $input->min = isset($input->min) ? max($input->min, $range[0]) : $range[0];
 79:                 }
 80:                 if (isset($range[1]) && is_scalar($range[1])) {
 81:                     $input->max = isset($input->max) ? min($input->max, $range[1]) : $range[1];
 82:                 }
 83: 
 84:             } elseif ($rule->validator === Form::PATTERN && is_scalar($rule->arg)
 85:                 && in_array($input->type, array('text', 'search', 'tel', 'url', 'email', 'password'), TRUE)
 86:             ) {
 87:                 $input->pattern = $rule->arg;
 88:             }
 89:         }
 90: 
 91:         if ($input->type !== 'password' && ($this->rawValue !== '' || $this->emptyValue !== '')) {
 92:             $input->value = $this->rawValue === ''
 93:                 ? $this->translate($this->emptyValue)
 94:                 : $this->rawValue;
 95:         }
 96:         return $input;
 97:     }
 98: 
 99: }
100: 
Nette 2.2 API documentation generated by ApiGen 2.8.0