| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | declare (strict_types=1); |
| 8 | 8 | namespace Packetery\Nette\Forms\Controls; |
| 9 | 9 | |
| 10 | -use Packetery\Nette; | |
| 10 | +use Packetery\Nette\Utils\Html; | |
| 11 | 11 | /** |
| 12 | 12 | * Push button control with no default behavior. |
| 13 | 13 | */ |
| 14 | 14 | class Button extends BaseControl |
| @@ -36,15 +36,27 @@ | ||
| 36 | 36 | public function getLabel($caption = null) |
| 37 | 37 | { |
| 38 | 38 | return null; |
| 39 | 39 | } |
| 40 | + /** @return static */ | |
| 41 | + public function renderAsButton(bool $state = \true) | |
| 42 | + { | |
| 43 | + $this->control->setName($state ? 'button' : 'input'); | |
| 44 | + return $this; | |
| 45 | + } | |
| 40 | 46 | /** |
| 41 | 47 | * Generates control's HTML element. |
| 42 | 48 | * @param string|object $caption |
| 43 | 49 | */ |
| 44 | - public function getControl($caption = null) : \Packetery\Nette\Utils\Html | |
| 50 | + public function getControl($caption = null) : Html | |
| 45 | 51 | { |
| 46 | 52 | $this->setOption('rendered', \true); |
| 47 | - $el = clone $this->control; | |
| 48 | - return $el->addAttributes(['name' => $this->getHtmlName(), 'disabled' => $this->isDisabled(), 'value' => $this->translate($caption ?? $this->getCaption())]); | |
| 53 | + $caption = $this->translate($caption ?? $this->getCaption()); | |
| 54 | + $el = (clone $this->control)->addAttributes(['name' => $this->getHtmlName(), 'disabled' => $this->isDisabled()]); | |
| 55 | + if ($caption instanceof Html || $caption !== null && $el->getName() === 'button') { | |
| 56 | + $el->setName('button')->setText($caption); | |
| 57 | + } else { | |
| 58 | + $el->value = $caption; | |
| 59 | + } | |
| 60 | + return $el; | |
| 49 | 61 | } |
| 50 | 62 | } |