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