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
  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: /**
 19:  * Submittable button control.
 20:  *
 21:  * @author     David Grudl
 22:  *
 23:  * @property-read bool $submittedBy
 24:  * @property   mixed $validationScope
 25:  */
 26: class SubmitButton extends Button implements Nette\Forms\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:         if ($this->value = is_scalar($value) && (bool) $value) {
 58:             $this->getForm()->setSubmittedBy($this);
 59:         }
 60:         return $this;
 61:     }
 62: 
 63: 
 64: 
 65:     /**
 66:      * Tells if the form was submitted by this button.
 67:      * @return bool
 68:      */
 69:     public function isSubmittedBy()
 70:     {
 71:         return $this->getForm()->isSubmitted() === $this;
 72:     }
 73: 
 74: 
 75: 
 76:     /**
 77:      * Sets the validation scope. Clicking the button validates only the controls within the specified scope.
 78:      * @param  mixed
 79:      * @return SubmitButton  provides a fluent interface
 80:      */
 81:     public function setValidationScope($scope)
 82:     {
 83:         // TODO: implement groups
 84:         $this->validationScope = (bool) $scope;
 85:         $this->control->formnovalidate = !$this->validationScope;
 86:         return $this;
 87:     }
 88: 
 89: 
 90: 
 91:     /**
 92:      * Gets the validation scope.
 93:      * @return mixed
 94:      */
 95:     final public function getValidationScope()
 96:     {
 97:         return $this->validationScope;
 98:     }
 99: 
100: 
101: 
102:     /**
103:      * Fires click event.
104:      * @return void
105:      */
106:     public function click()
107:     {
108:         $this->onClick($this);
109:     }
110: 
111: 
112: 
113:     /**
114:      * Submitted validator: has been button pressed?
115:      * @param  Nette\Forms\ISubmitterControl
116:      * @return bool
117:      */
118:     public static function validateSubmitted(Nette\Forms\ISubmitterControl $control)
119:     {
120:         return $control->isSubmittedBy();
121:     }
122: 
123: }
124: 
Nette Framework 2.0.0 API API documentation generated by ApiGen 2.7.0