Source for file TextInput.php

Documentation is available at TextInput.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see https://nette.org
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    https://nette.org/license  Nette license
  15. 15:  * @link       https://nette.org
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Forms
  18. 18:  * @version    $Id$
  19. 19:  */
  20. 20:  
  21. 21:  
  22. 22:  
  23. 23: require_once dirname(__FILE__'/../../Forms/Controls/TextBase.php';
  24. 24:  
  25. 25:  
  26. 26:  
  27. 27: /**
  28. 28:  * Single line text input control.
  29. 29:  *
  30. 30:  * @author     David Grudl
  31. 31:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  32. 32:  * @package    Nette\Forms
  33. 33:  */
  34. 34: class TextInput extends TextBase
  35. 35: {
  36. 36:  
  37. 37:     /**
  38. 38:      * @param  string  control name
  39. 39:      * @param  string  label
  40. 40:      * @param  int  width of the control
  41. 41:      * @param  int  maximum number of characters the user may enter
  42. 42:      */
  43. 43:     public function __construct($label$cols NULL$maxLength NULL)
  44. 44:     {
  45. 45:         parent::__construct($label);
  46. 46:         $this->control->type 'text';
  47. 47:         $this->control->size $cols;
  48. 48:         $this->control->maxlength $maxLength;
  49. 49:         $this->filters['trim';
  50. 50:         $this->value = '';
  51. 51:     }
  52. 52:  
  53. 53:  
  54. 54:  
  55. 55:     /**
  56. 56:      * Loads HTTP data.
  57. 57:      * @param  array 
  58. 58:      * @return void 
  59. 59:      */
  60. 60:     public function loadHttpData($data)
  61. 61:     {
  62. 62:         parent::loadHttpData($data);
  63. 63:  
  64. 64:         if ($this->control->type === 'password'{
  65. 65:             $this->tmpValue = '';
  66. 66:         }
  67. 67:  
  68. 68:         if ($this->control->maxlength && iconv_strlen($this->value'UTF-8'$this->control->maxlength{
  69. 69:             $this->value = iconv_substr($this->value0$this->control->maxlength'UTF-8');
  70. 70:         }
  71. 71:     }
  72. 72:  
  73. 73:  
  74. 74:  
  75. 75:     /**
  76. 76:      * Sets or unsets the password mode.
  77. 77:      * @param  bool 
  78. 78:      * @return TextInput  provides a fluent interface
  79. 79:      */
  80. 80:     public function setPasswordMode($mode TRUE)
  81. 81:     {
  82. 82:         $this->control->type $mode 'password' 'text';
  83. 83:         return $this;
  84. 84:     }
  85. 85:  
  86. 86:  
  87. 87:  
  88. 88:     /**
  89. 89:      * Generates control's HTML element.
  90. 90:      * @return Html 
  91. 91:      */
  92. 92:     public function getControl()
  93. 93:     {
  94. 94:         $control parent::getControl();
  95. 95:         $control->value $this->value === '' $this->translate($this->emptyValue$this->tmpValue;
  96. 96:         return $control;
  97. 97:     }
  98. 98:  
  99. 99:  
  100. 100:  
  101. 101:     public function notifyRule(Rule $rule)
  102. 102:     {
  103. 103:         if (is_string($rule->operation&& strcasecmp($rule->operation':length'=== 0{
  104. 104:             $this->control->maxlength is_array($rule->arg$rule->arg[1$rule->arg;
  105. 105:  
  106. 106:         elseif (is_string($rule->operation&& strcasecmp($rule->operation':maxLength'=== 0{
  107. 107:             $this->control->maxlength $rule->arg;
  108. 108:         }
  109. 109:  
  110. 110:         parent::notifyRule($rule);
  111. 111:     }
  112. 112:  
  113. 113: