Packages

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

Classes

  • NButton
  • NCheckbox
  • NHiddenField
  • NImageButton
  • NMultiSelectBox
  • NRadioList
  • NSelectBox
  • NSubmitButton
  • NTextArea
  • NTextBase
  • NTextInput
  • NUploadControl
  • 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, 2011 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:  * @package Nette\Forms\Controls
 20:  */
 21: class NTextInput extends NTextBase
 22: {
 23: 
 24:     /**
 25:      * @param  string  control name
 26:      * @param  string  label
 27:      * @param  int  width of the control
 28:      * @param  int  maximum number of characters the user may enter
 29:      */
 30:     public function __construct($label = NULL, $cols = NULL, $maxLength = NULL)
 31:     {
 32:         parent::__construct($label);
 33:         $this->control->type = 'text';
 34:         $this->control->size = $cols;
 35:         $this->control->maxlength = $maxLength;
 36:         $this->filters[] = callback($this, 'sanitize');
 37:         $this->value = '';
 38:     }
 39: 
 40: 
 41: 
 42:     /**
 43:      * Filter: removes unnecessary whitespace and shortens value to control's max length.
 44:      * @return string
 45:      */
 46:     public function sanitize($value)
 47:     {
 48:         if ($this->control->maxlength && NStrings::length($value) > $this->control->maxlength) {
 49:             $value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
 50:         }
 51:         return NStrings::trim(strtr($value, "\r\n", '  '));
 52:     }
 53: 
 54: 
 55: 
 56:     /**
 57:      * Changes control's type attribute.
 58:      * @param  string
 59:      * @return NFormControl  provides a fluent interface
 60:      */
 61:     public function setType($type)
 62:     {
 63:         $this->control->type = $type;
 64:         return $this;
 65:     }
 66: 
 67: 
 68: 
 69:     /** @deprecated */
 70:     public function setPasswordMode($mode = TRUE)
 71:     {
 72:         $this->control->type = $mode ? 'password' : 'text';
 73:         return $this;
 74:     }
 75: 
 76: 
 77: 
 78:     /**
 79:      * Generates control's HTML element.
 80:      * @return NHtml
 81:      */
 82:     public function getControl()
 83:     {
 84:         $control = parent::getControl();
 85:         foreach ($this->getRules() as $rule) {
 86:             if ($rule->isNegative || $rule->type !== NRule::VALIDATOR) {
 87: 
 88:             } elseif ($rule->operation === NForm::RANGE && $control->type !== 'text') {
 89:                 list($control->min, $control->max) = $rule->arg;
 90: 
 91:             } elseif ($rule->operation === NForm::PATTERN) {
 92:                 $control->pattern = $rule->arg;
 93:             }
 94:         }
 95:         if ($control->type !== 'password') {
 96:             $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value;
 97:         }
 98:         return $control;
 99:     }
100: 
101: }
102: 
Nette Framework 2.0beta1 (for PHP 5.2) API API documentation generated by ApiGen 2.3.0