Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Diagnostics
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
      • Diagnostics
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • PhpGenerator
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
  • NetteModule
  • 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
  • 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: 
 12: 
 13: /**
 14:  * Single line text input control.
 15:  *
 16:  * @author     David Grudl
 17:  * @property-write $type
 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(Nette\Forms\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:     /** @deprecated */
 57:     public function setPasswordMode($mode = TRUE)
 58:     {
 59:         trigger_error(__METHOD__ . '() is deprecated; use setType("password") instead.', E_USER_DEPRECATED);
 60:         $this->control->type = $mode ? 'password' : 'text';
 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->type !== Nette\Forms\Rule::VALIDATOR) {
 75: 
 76:             } elseif ($rule->operation === Nette\Forms\Form::RANGE
 77:                 && in_array($input->type, array('number', 'range', 'datetime-local', 'datetime', 'date', 'month', 'week', 'time'), TRUE)
 78:             ) {
 79:                 if (isset($rule->arg[0]) && is_scalar($rule->arg[0])) {
 80:                     $input->min = isset($input->min) ? max($input->min, $rule->arg[0]) : $rule->arg[0];
 81:                 }
 82:                 if (isset($rule->arg[1]) && is_scalar($rule->arg[1])) {
 83:                     $input->max = isset($input->max) ? min($input->max, $rule->arg[1]) : $rule->arg[1];
 84:                 }
 85: 
 86:             } elseif ($rule->operation === Nette\Forms\Form::PATTERN && is_scalar($rule->arg)
 87:                 && in_array($input->type, array('text', 'search', 'tel', 'url', 'email', 'password'), TRUE)
 88:             ) {
 89:                 $input->pattern = $rule->arg;
 90:             }
 91:         }
 92: 
 93:         if ($input->type !== 'password') {
 94:             $input->value = $this->rawValue === '' ? $this->translate($this->emptyValue) : $this->rawValue;
 95:         }
 96:         return $input;
 97:     }
 98: 
 99: }
100: 
Nette 2.1 API documentation generated by ApiGen 2.8.0