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->filters[array($this'checkMaxLength');
  50. 50:         $this->value = '';
  51. 51:     }
  52. 52:  
  53. 53:  
  54. 54:  
  55. 55:     /**
  56. 56:      * Filter: shortens value to control's max length.
  57. 57:      * @return string 
  58. 58:      */
  59. 59:     protected function checkMaxLength($value)
  60. 60:     {
  61. 61:         if ($this->control->maxlength && iconv_strlen($value'UTF-8'$this->control->maxlength{
  62. 62:             $value iconv_substr($value0$this->control->maxlength'UTF-8');
  63. 63:         }
  64. 64:         return $value;
  65. 65:     }
  66. 66:  
  67. 67:  
  68. 68:  
  69. 69:     /**
  70. 70:      * Sets or unsets the password mode.
  71. 71:      * @param  bool 
  72. 72:      * @return TextInput  provides a fluent interface
  73. 73:      */
  74. 74:     public function setPasswordMode($mode TRUE)
  75. 75:     {
  76. 76:         $this->control->type $mode 'password' 'text';
  77. 77:         return $this;
  78. 78:     }
  79. 79:  
  80. 80:  
  81. 81:  
  82. 82:     /**
  83. 83:      * Generates control's HTML element.
  84. 84:      * @return Html 
  85. 85:      */
  86. 86:     public function getControl()
  87. 87:     {
  88. 88:         $control parent::getControl();
  89. 89:         if ($this->control->type !== 'password'{
  90. 90:             $control->value $this->getValue(=== '' $this->translate($this->emptyValue$this->value;
  91. 91:         }
  92. 92:         return $control;
  93. 93:     }
  94. 94:  
  95. 95:  
  96. 96:  
  97. 97:     public function notifyRule(Rule $rule)
  98. 98:     {
  99. 99:         if (is_string($rule->operation&& strcasecmp($rule->operation':length'=== && !$rule->isNegative{
  100. 100:             $this->control->maxlength is_array($rule->arg$rule->arg[1$rule->arg;
  101. 101:  
  102. 102:         elseif (is_string($rule->operation&& strcasecmp($rule->operation':maxLength'=== && !$rule->isNegative{
  103. 103:             $this->control->maxlength $rule->arg;
  104. 104:         }
  105. 105:  
  106. 106:         parent::notifyRule($rule);
  107. 107:     }
  108. 108:  
  109. 109: