-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MartkCz
committed
Jun 20, 2018
1 parent
32bd064
commit 9e5d3f1
Showing
4 changed files
with
108 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace WebChemistry\Forms\Controls\Buttons; | ||
|
||
use Nette\Forms\Container; | ||
use Nette\Forms\Controls\SubmitButton; | ||
use Nette\SmartObject; | ||
use WebChemistry\Forms\Controls\Multiplier; | ||
|
||
class RemoveButton { | ||
|
||
use SmartObject; | ||
|
||
/** @var null|string */ | ||
private $caption; | ||
|
||
/** @var array */ | ||
public $onCreate = []; | ||
|
||
/** @var array */ | ||
private $classes = []; | ||
|
||
/** | ||
* @param $caption string|null | ||
*/ | ||
public function __construct($caption) { | ||
$this->caption = $caption; | ||
} | ||
|
||
/** | ||
* @param callable $onCreate | ||
* @return static | ||
*/ | ||
public function addOnCreateCallback(callable $onCreate) { | ||
$this->onCreate[] = $onCreate; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $class | ||
* @return static | ||
*/ | ||
public function addClass($class) { | ||
$this->classes[] = $class; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param Multiplier $multiplier | ||
* @return SubmitButton | ||
*/ | ||
public function create(Multiplier $multiplier) { | ||
$button = new SubmitButton($this->caption); | ||
|
||
$button->setHtmlAttribute('class', implode(' ', $this->classes)); | ||
$button->setValidationScope([]) | ||
->setOmitted(); | ||
|
||
$button->onClick[] = $button->onInvalidClick[] = [$multiplier, 'resetFormEvents']; | ||
|
||
foreach ($this->onCreate as $callback) { | ||
$callback($button); | ||
} | ||
|
||
return $button; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters