/Nette/Forms/Controls/SubmitButton.php
PHP | 139 lines | 45 code | 33 blank | 61 comment | 3 complexity | 9c27e55fe98308942ba492e32c04e7e2 MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php
- /**
- * Nette Framework
- *
- * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
- *
- * This source file is subject to the "Nette license" that is bundled
- * with this package in the file license.txt.
- *
- * For more information please see http://nettephp.com
- *
- * @copyright Copyright (c) 2004, 2009 David Grudl
- * @license http://nettephp.com/license Nette license
- * @link http://nettephp.com
- * @category Nette
- * @package Nette\Forms
- */
- /*namespace Nette\Forms;*/
- require_once dirname(__FILE__) . '/../../Forms/Controls/Button.php';
- require_once dirname(__FILE__) . '/../../Forms/ISubmitterControl.php';
- /**
- * Submittable button control.
- *
- * @author David Grudl
- * @copyright Copyright (c) 2004, 2009 David Grudl
- * @package Nette\Forms
- *
- * @property mixed $validationScope
- * @property-read bool $submittedBy
- */
- class SubmitButton extends Button implements ISubmitterControl
- {
- /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is successfully validated */
- public $onClick;
- /** @var array of function(SubmitButton $sender); Occurs when the button is clicked and form is not validated */
- public $onInvalidClick;
- /** @var mixed */
- private $validationScope = TRUE;
- /**
- * @param string caption
- */
- public function __construct($caption = NULL)
- {
- parent::__construct($caption);
- $this->control->type = 'submit';
- }
- /**
- * Sets 'pressed' indicator.
- * @param bool
- * @return SubmitButton provides a fluent interface
- */
- public function setValue($value)
- {
- $this->value = is_scalar($value) && (bool) $value;
- $form = $this->getForm();
- if ($this->value || !is_object($form->isSubmitted())) {
- $this->value = TRUE;
- $form->setSubmittedBy($this);
- }
- return $this;
- }
- /**
- * Tells if the form was submitted by this button.
- * @return bool
- */
- public function isSubmittedBy()
- {
- return $this->getForm()->isSubmitted() === $this;
- }
- /**
- * Sets the validation scope. Clicking the button validates only the controls within the specified scope.
- * @param mixed
- * @return SubmitButton provides a fluent interface
- */
- public function setValidationScope($scope)
- {
- // TODO: implement groups
- $this->validationScope = (bool) $scope;
- return $this;
- }
- /**
- * Gets the validation scope.
- * @return mixed
- */
- final public function getValidationScope()
- {
- return $this->validationScope;
- }
- /**
- * Fires click event.
- * @return void
- */
- public function click()
- {
- $this->onClick($this);
- }
- /**
- * Submitted validator: has been button pressed?
- * @param ISubmitterControl
- * @return bool
- */
- public static function validateSubmitted(ISubmitterControl $control)
- {
- return $control->isSubmittedBy();
- }
- }