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