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

Classes

  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6:  * @package Nette\Forms\Controls
  7:  */
  8: 
  9: 
 10: 
 11: /**
 12:  * Submittable button control.
 13:  *
 14:  * @author     David Grudl
 15:  *
 16:  * @property-read bool $submittedBy
 17:  * @property   mixed $validationScope
 18:  * @package Nette\Forms\Controls
 19:  */
 20: class NSubmitButton extends NButton implements ISubmitterControl
 21: {
 22:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
 23:     public $onClick;
 24: 
 25:     /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is not validated */
 26:     public $onInvalidClick;
 27: 
 28:     /** @var mixed */
 29:     private $validationScope = TRUE;
 30: 
 31: 
 32:     /**
 33:      * @param  string  caption
 34:      */
 35:     public function __construct($caption = NULL)
 36:     {
 37:         parent::__construct($caption);
 38:         $this->control->type = 'submit';
 39:     }
 40: 
 41: 
 42:     /**
 43:      * Sets 'pressed' indicator.
 44:      * @param  bool
 45:      * @return self
 46:      */
 47:     public function setValue($value)
 48:     {
 49:         if ($this->value = $value !== NULL) {
 50:             $this->getForm()->setSubmittedBy($this);
 51:         }
 52:         return $this;
 53:     }
 54: 
 55: 
 56:     /**
 57:      * Tells if the form was submitted by this button.
 58:      * @return bool
 59:      */
 60:     public function isSubmittedBy()
 61:     {
 62:         return $this->getForm()->isSubmitted() === $this;
 63:     }
 64: 
 65: 
 66:     /**
 67:      * Sets the validation scope. Clicking the button validates only the controls within the specified scope.
 68:      * @param  mixed
 69:      * @return self
 70:      */
 71:     public function setValidationScope($scope)
 72:     {
 73:         $this->validationScope = (bool) $scope;
 74:         $this->control->formnovalidate = !$this->validationScope;
 75:         return $this;
 76:     }
 77: 
 78: 
 79:     /**
 80:      * Gets the validation scope.
 81:      * @return mixed
 82:      */
 83:     public function getValidationScope()
 84:     {
 85:         return $this->validationScope;
 86:     }
 87: 
 88: 
 89:     /**
 90:      * Fires click event.
 91:      * @return void
 92:      */
 93:     public function click()
 94:     {
 95:         $this->onClick($this);
 96:     }
 97: 
 98: 
 99:     /**
100:      * Submitted validator: has been button pressed?
101:      * @return bool
102:      * @internal
103:      */
104:     public static function validateSubmitted(ISubmitterControl $control)
105:     {
106:         return $control->isSubmittedBy();
107:     }
108: 
109: }
110: 
Nette Framework 2.0.18 (for PHP 5.2, prefixed) API documentation generated by ApiGen 2.8.0