1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\Forms\Controls;
9:
10: use Nette;
11:
12:
13: /**
14: * Push button control with no default behavior.
15: */
16: class Button extends BaseControl
17: {
18:
19: /**
20: * @param string|object
21: */
22: public function __construct($caption = null)
23: {
24: parent::__construct($caption);
25: $this->control->type = 'button';
26: $this->setOption('type', 'button');
27: }
28:
29:
30: /**
31: * Is button pressed?
32: * @return bool
33: */
34: public function isFilled()
35: {
36: $value = $this->getValue();
37: return $value !== null && $value !== [];
38: }
39:
40:
41: /**
42: * Bypasses label generation.
43: * @return void
44: */
45: public function getLabel($caption = null)
46: {
47: }
48:
49:
50: /**
51: * Generates control's HTML element.
52: * @param string|object
53: * @return Nette\Utils\Html
54: */
55: public function getControl($caption = null)
56: {
57: $this->setOption('rendered', true);
58: $el = clone $this->control;
59: return $el->addAttributes([
60: 'name' => $this->getHtmlName(),
61: 'disabled' => $this->isDisabled(),
62: 'value' => $this->translate($caption === null ? $this->caption : $caption),
63: ]);
64: }
65: }
66: