Packages

  • 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

  • NButton
  • NCheckbox
  • NFormControl
  • NHiddenField
  • NImageButton
  • NMultiSelectBox
  • NRadioList
  • NSelectBox
  • NSubmitButton
  • NTextArea
  • NTextBase
  • NTextInput
  • NUploadControl
  • Overview
  • Package
  • 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:  * @package Nette\Forms\Controls
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Submittable button control.
 17:  *
 18:  * @author     David Grudl
 19:  *
 20:  * @property-read bool $submittedBy
 21:  * @property   mixed $validationScope
 22:  * @package Nette\Forms\Controls
 23:  */
 24: class NSubmitButton extends NButton implements ISubmitterControl
 25: {
 26:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
 27:     public $onClick;
 28: 
 29:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is not validated */
 30:     public $onInvalidClick;
 31: 
 32:     /** @var mixed */
 33:     private $validationScope = TRUE;
 34: 
 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:     /**
 49:      * Sets 'pressed' indicator.
 50:      * @param  bool
 51:      * @return NSubmitButton  provides a fluent interface
 52:      */
 53:     public function setValue($value)
 54:     {
 55:         if ($this->value = $value !== NULL) {
 56:             $this->getForm()->setSubmittedBy($this);
 57:         }
 58:         return $this;
 59:     }
 60: 
 61: 
 62: 
 63:     /**
 64:      * Tells if the form was submitted by this button.
 65:      * @return bool
 66:      */
 67:     public function isSubmittedBy()
 68:     {
 69:         return $this->getForm()->isSubmitted() === $this;
 70:     }
 71: 
 72: 
 73: 
 74:     /**
 75:      * Sets the validation scope. Clicking the button validates only the controls within the specified scope.
 76:      * @param  mixed
 77:      * @return NSubmitButton  provides a fluent interface
 78:      */
 79:     public function setValidationScope($scope)
 80:     {
 81:         // TODO: implement groups
 82:         $this->validationScope = (bool) $scope;
 83:         $this->control->formnovalidate = !$this->validationScope;
 84:         return $this;
 85:     }
 86: 
 87: 
 88: 
 89:     /**
 90:      * Gets the validation scope.
 91:      * @return mixed
 92:      */
 93:     final public function getValidationScope()
 94:     {
 95:         return $this->validationScope;
 96:     }
 97: 
 98: 
 99: 
100:     /**
101:      * Fires click event.
102:      * @return void
103:      */
104:     public function click()
105:     {
106:         $this->onClick($this);
107:     }
108: 
109: 
110: 
111:     /**
112:      * Submitted validator: has been button pressed?
113:      * @param  ISubmitterControl
114:      * @return bool
115:      */
116:     public static function validateSubmitted(ISubmitterControl $control)
117:     {
118:         return $control->isSubmittedBy();
119:     }
120: 
121: }
122: 
Nette Framework 2.0.4 (for PHP 5.2, prefixed) API API documentation generated by ApiGen 2.7.0