Namespaces

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

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:     Nette\Utils\Strings;
 13: 
 14: 
 15: /**
 16:  * Implements the basic functionality common to text input controls.
 17:  *
 18:  * @author     David Grudl
 19:  *
 20:  * @property   string $emptyValue
 21:  */
 22: abstract class TextBase extends BaseControl
 23: {
 24:     /** @var string */
 25:     protected $emptyValue = '';
 26: 
 27:     /** @var mixed unfiltered submitted value */
 28:     protected $rawValue = '';
 29: 
 30: 
 31:     /**
 32:      * Sets control's value.
 33:      * @param  string
 34:      * @return self
 35:      */
 36:     public function setValue($value)
 37:     {
 38:         if ($value === NULL) {
 39:             $value = '';
 40:         } elseif (!is_scalar($value) && !method_exists($value, '__toString')) {
 41:             throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or NULL, %s given in field '%s'.", gettype($value), $this->name));
 42:         }
 43:         $this->rawValue = $this->value = $value;
 44:         return $this;
 45:     }
 46: 
 47: 
 48:     /**
 49:      * Returns control's value.
 50:      * @return string
 51:      */
 52:     public function getValue()
 53:     {
 54:         return $this->value === Strings::trim($this->translate($this->emptyValue)) ? '' : $this->value;
 55:     }
 56: 
 57: 
 58:     /**
 59:      * Sets the special value which is treated as empty string.
 60:      * @param  string
 61:      * @return self
 62:      */
 63:     public function setEmptyValue($value)
 64:     {
 65:         $this->emptyValue = (string) $value;
 66:         return $this;
 67:     }
 68: 
 69: 
 70:     /**
 71:      * Returns the special value which is treated as empty string.
 72:      * @return string
 73:      */
 74:     public function getEmptyValue()
 75:     {
 76:         return $this->emptyValue;
 77:     }
 78: 
 79: 
 80:     /**
 81:      * Sets the maximum number of allowed characters.
 82:      * @param  int
 83:      * @return self
 84:      */
 85:     public function setMaxLength($length)
 86:     {
 87:         $this->control->maxlength = $length;
 88:         return $this;
 89:     }
 90: 
 91: 
 92:     /**
 93:      * Appends input string filter callback.
 94:      * @param  callable
 95:      * @return self
 96:      */
 97:     public function addFilter($filter)
 98:     {
 99:         $this->rules->addFilter($filter);
100:         return $this;
101:     }
102: 
103: 
104:     public function getControl()
105:     {
106:         $el = parent::getControl();
107:         if ($this->emptyValue !== '') {
108:             $el->attrs['data-nette-empty-value'] = Strings::trim($this->translate($this->emptyValue));
109:         }
110:         if (isset($el->placeholder)) {
111:             $el->placeholder = $this->translate($el->placeholder);
112:         }
113:         return $el;
114:     }
115: 
116: 
117:     public function addRule($validator, $message = NULL, $arg = NULL)
118:     {
119:         if ($validator === Form::LENGTH || $validator === Form::MAX_LENGTH) {
120:             $tmp = is_array($arg) ? $arg[1] : $arg;
121:             if (is_scalar($tmp)) {
122:                 $this->control->maxlength = isset($this->control->maxlength) ? min($this->control->maxlength, $tmp) : $tmp;
123:             }
124:         }
125:         return parent::addRule($validator, $message, $arg);
126:     }
127: 
128: }
129: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0