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