Namespaces

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

  • Button
  • Checkbox
  • ConventionalRenderer
  • FileUpload
  • Form
  • FormContainer
  • FormControl
  • FormGroup
  • HiddenField
  • ImageButton
  • InstantClientScript
  • MultiSelectBox
  • RadioList
  • Rule
  • Rules
  • SelectBox
  • SubmitButton
  • TextArea
  • TextBase
  • TextInput

Interfaces

  • IFormControl
  • IFormRenderer
  • INamingContainer
  • ISubmitterControl
  • Overview
  • Namespace
  • Class
  • Tree
  • Other releases
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette\Forms;
 13: 
 14: use Nette;
 15: 
 16: 
 17: 
 18: /**
 19:  * Submittable button control.
 20:  *
 21:  * @author     David Grudl
 22:  *
 23:  * @property   mixed $validationScope
 24:  * @property-read bool $submittedBy
 25:  */
 26: class SubmitButton extends Button implements ISubmitterControl
 27: {
 28:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
 29:     public $onClick;
 30: 
 31:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is not validated */
 32:     public $onInvalidClick;
 33: 
 34:     /** @var mixed */
 35:     private $validationScope = TRUE;
 36: 
 37: 
 38: 
 39:     /**
 40:      * @param  string  caption
 41:      */
 42:     public function __construct($caption = NULL)
 43:     {
 44:         parent::__construct($caption);
 45:         $this->control->type = 'submit';
 46:     }
 47: 
 48: 
 49: 
 50:     /**
 51:      * Sets 'pressed' indicator.
 52:      * @param  bool
 53:      * @return SubmitButton  provides a fluent interface
 54:      */
 55:     public function setValue($value)
 56:     {
 57:         $this->value = is_scalar($value) && (bool) $value;
 58:         $form = $this->getForm();
 59:         if ($this->value || !is_object($form->isSubmitted())) {
 60:             $this->value = TRUE;
 61:             $form->setSubmittedBy($this);
 62:         }
 63:         return $this;
 64:     }
 65: 
 66: 
 67: 
 68:     /**
 69:      * Tells if the form was submitted by this button.
 70:      * @return bool
 71:      */
 72:     public function isSubmittedBy()
 73:     {
 74:         return $this->getForm()->isSubmitted() === $this;
 75:     }
 76: 
 77: 
 78: 
 79:     /**
 80:      * Sets the validation scope. Clicking the button validates only the controls within the specified scope.
 81:      * @param  mixed
 82:      * @return SubmitButton  provides a fluent interface
 83:      */
 84:     public function setValidationScope($scope)
 85:     {
 86:         // TODO: implement groups
 87:         $this->validationScope = (bool) $scope;
 88:         return $this;
 89:     }
 90: 
 91: 
 92: 
 93:     /**
 94:      * Gets the validation scope.
 95:      * @return mixed
 96:      */
 97:     final public function getValidationScope()
 98:     {
 99:         return $this->validationScope;
100:     }
101: 
102: 
103: 
104:     /**
105:      * Fires click event.
106:      * @return void
107:      */
108:     public function click()
109:     {
110:         $this->onClick($this);
111:     }
112: 
113: 
114: 
115:     /**
116:      * Submitted validator: has been button pressed?
117:      * @param  ISubmitterControl
118:      * @return bool
119:      */
120:     public static function validateSubmitted(ISubmitterControl $control)
121:     {
122:         return $control->isSubmittedBy();
123:     }
124: 
125: }
126: 
Nette Framework 0.9.7 API documentation generated by ApiGen 2.3.0