Packages

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • Button
  • Checkbox
  • FormControl
  • HiddenField
  • ImageButton
  • MultiSelectBox
  • RadioList
  • SelectBox
  • SubmitButton
  • TextArea
  • TextBase
  • TextInput
  • UploadControl
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  * @package Nette\Forms\Controls
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Single line text input control.
 17:  *
 18:  * @author     David Grudl
 19:  * @property-write $type
 20:  * @package Nette\Forms\Controls
 21:  */
 22: class TextInput extends TextBase
 23: {
 24: 
 25:     /**
 26:      * @param  string  control name
 27:      * @param  string  label
 28:      * @param  int  width of the control
 29:      * @param  int  maximum number of characters the user may enter
 30:      */
 31:     public function __construct($label = NULL, $cols = NULL, $maxLength = NULL)
 32:     {
 33:         parent::__construct($label);
 34:         $this->control->type = 'text';
 35:         $this->control->size = $cols;
 36:         $this->control->maxlength = $maxLength;
 37:         $this->filters[] = callback($this, 'sanitize');
 38:         $this->value = '';
 39:     }
 40: 
 41: 
 42: 
 43:     /**
 44:      * Filter: removes unnecessary whitespace and shortens value to control's max length.
 45:      * @return string
 46:      */
 47:     public function sanitize($value)
 48:     {
 49:         if ($this->control->maxlength && Strings::length($value) > $this->control->maxlength) {
 50:             $value = Strings::substring($value, 0, $this->control->maxlength);
 51:         }
 52:         return Strings::trim(strtr($value, "\r\n", '  '));
 53:     }
 54: 
 55: 
 56: 
 57:     /**
 58:      * Changes control's type attribute.
 59:      * @param  string
 60:      * @return FormControl  provides a fluent interface
 61:      */
 62:     public function setType($type)
 63:     {
 64:         $this->control->type = $type;
 65:         return $this;
 66:     }
 67: 
 68: 
 69: 
 70:     /** @deprecated */
 71:     public function setPasswordMode($mode = TRUE)
 72:     {
 73:         $this->control->type = $mode ? 'password' : 'text';
 74:         return $this;
 75:     }
 76: 
 77: 
 78: 
 79:     /**
 80:      * Generates control's HTML element.
 81:      * @return Html
 82:      */
 83:     public function getControl()
 84:     {
 85:         $control = parent::getControl();
 86:         foreach ($this->getRules() as $rule) {
 87:             if ($rule->isNegative || $rule->type !== Rule::VALIDATOR) {
 88: 
 89:             } elseif ($rule->operation === Form::RANGE && $control->type !== 'text') {
 90:                 list($control->min, $control->max) = $rule->arg;
 91: 
 92:             } elseif ($rule->operation === Form::PATTERN) {
 93:                 $control->pattern = $rule->arg;
 94:             }
 95:         }
 96:         if ($control->type !== 'password') {
 97:             $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value;
 98:         }
 99:         return $control;
100:     }
101: 
102: }
103: 
Nette Framework 2.0.0 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.7.0