Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • BaseControl
  • Button
  • Checkbox
  • HiddenField
  • ImageButton
  • MultiSelectBox
  • RadioList
  • SelectBox
  • SubmitButton
  • TextArea
  • TextBase
  • TextInput
  • UploadControl
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://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\Controls;
 13: 
 14: use Nette;
 15: 
 16: 
 17: /**
 18:  * Submittable button control.
 19:  *
 20:  * @author     David Grudl
 21:  *
 22:  * @property-read bool $submittedBy
 23:  * @property   mixed $validationScope
 24:  */
 25: class SubmitButton extends Button implements Nette\Forms\ISubmitterControl
 26: {
 27:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
 28:     public $onClick;
 29: 
 30:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is not validated */
 31:     public $onInvalidClick;
 32: 
 33:     /** @var mixed */
 34:     private $validationScope = TRUE;
 35: 
 36: 
 37:     /**
 38:      * @param  string  caption
 39:      */
 40:     public function __construct($caption = NULL)
 41:     {
 42:         parent::__construct($caption);
 43:         $this->control->type = 'submit';
 44:     }
 45: 
 46: 
 47:     /**
 48:      * Sets 'pressed' indicator.
 49:      * @param  bool
 50:      * @return self
 51:      */
 52:     public function setValue($value)
 53:     {
 54:         if ($this->value = $value !== NULL) {
 55:             $this->getForm()->setSubmittedBy($this);
 56:         }
 57:         return $this;
 58:     }
 59: 
 60: 
 61:     /**
 62:      * Tells if the form was submitted by this button.
 63:      * @return bool
 64:      */
 65:     public function isSubmittedBy()
 66:     {
 67:         return $this->getForm()->isSubmitted() === $this;
 68:     }
 69: 
 70: 
 71:     /**
 72:      * Sets the validation scope. Clicking the button validates only the controls within the specified scope.
 73:      * @param  mixed
 74:      * @return self
 75:      */
 76:     public function setValidationScope($scope)
 77:     {
 78:         // TODO: implement groups
 79:         $this->validationScope = (bool) $scope;
 80:         $this->control->formnovalidate = !$this->validationScope;
 81:         return $this;
 82:     }
 83: 
 84: 
 85:     /**
 86:      * Gets the validation scope.
 87:      * @return mixed
 88:      */
 89:     final public function getValidationScope()
 90:     {
 91:         return $this->validationScope;
 92:     }
 93: 
 94: 
 95:     /**
 96:      * Fires click event.
 97:      * @return void
 98:      */
 99:     public function click()
100:     {
101:         $this->onClick($this);
102:     }
103: 
104: 
105:     /**
106:      * Submitted validator: has been button pressed?
107:      * @return bool
108:      */
109:     public static function validateSubmitted(Nette\Forms\ISubmitterControl $control)
110:     {
111:         return $control->isSubmittedBy();
112:     }
113: 
114: }
115: 
Nette Framework 2.0.11 API API documentation generated by ApiGen 2.8.0