Source for file SubmitButton.php

Documentation is available at SubmitButton.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/Button.php';
  23. 23:  
  24. 24: require_once dirname(__FILE__'/../../Forms/ISubmitterControl.php';
  25. 25:  
  26. 26:  
  27. 27:  
  28. 28: /**
  29. 29:  * Submittable button control.
  30. 30:  *
  31. 31:  * @author     David Grudl
  32. 32:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  33. 33:  * @package    Nette\Forms
  34. 34:  *
  35. 35:  * @property   mixed $validationScope 
  36. 36:  * @property-read bool $submittedBy 
  37. 37:  */
  38. 38: class SubmitButton extends Button implements ISubmitterControl
  39. 39: {
  40. 40:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
  41. 41:     public $onClick;
  42. 42:  
  43. 43:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is not validated */
  44. 44:     public $onInvalidClick;
  45. 45:  
  46. 46:     /** @var mixed */
  47. 47:     private $validationScope TRUE;
  48. 48:  
  49. 49:  
  50. 50:  
  51. 51:     /**
  52. 52:      * @param  string  caption
  53. 53:      */
  54. 54:     public function __construct($caption NULL)
  55. 55:     {
  56. 56:         parent::__construct($caption);
  57. 57:         $this->control->type 'submit';
  58. 58:     }
  59. 59:  
  60. 60:  
  61. 61:  
  62. 62:     /**
  63. 63:      * Tells if the form was submitted by this button.
  64. 64:      * @return bool 
  65. 65:      */
  66. 66:     public function isSubmittedBy()
  67. 67:     {
  68. 68:         return (bool) $this->value;
  69. 69:     }
  70. 70:  
  71. 71:  
  72. 72:  
  73. 73:     /**
  74. 74:      * Sets the validation scope. Clicking the button validates only the controls within the specified scope.
  75. 75:      * @param  mixed 
  76. 76:      * @return SubmitButton  provides a fluent interface
  77. 77:      */
  78. 78:     public function setValidationScope($scope)
  79. 79:     {
  80. 80:         // TODO: implement groups
  81. 81:         $this->validationScope = (bool) $scope;
  82. 82:         return $this;
  83. 83:     }
  84. 84:  
  85. 85:  
  86. 86:  
  87. 87:     /**
  88. 88:      * Gets the validation scope.
  89. 89:      * @return mixed 
  90. 90:      */
  91. 91:     final public function getValidationScope()
  92. 92:     {
  93. 93:         return $this->validationScope;
  94. 94:     }
  95. 95:  
  96. 96:  
  97. 97:  
  98. 98:     /**
  99. 99:      * Fires click event.
  100. 100:      * @return void 
  101. 101:      */
  102. 102:     public function click()
  103. 103:     {
  104. 104:         $this->onClick($this);
  105. 105:     }
  106. 106:  
  107. 107:  
  108. 108:  
  109. 109:     /**
  110. 110:      * Submitted validator: has been button pressed?
  111. 111:      * @param  ISubmitterControl 
  112. 112:      * @return bool 
  113. 113:      */
  114. 114:     public static function validateSubmitted(ISubmitterControl $control)
  115. 115:     {
  116. 116:         return $control->isSubmittedBy();
  117. 117:     }
  118. 118: