1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +02:00

Add option for InputfieldHidden to still render as an input in renderValue mode

This commit is contained in:
Ryan Cramer
2017-04-19 10:03:30 -04:00
parent c259ce8103
commit e83ed750c9

View File

@@ -3,6 +3,8 @@
/** /**
* An Inputfield for handling XHTML "hidden" form inputs * An Inputfield for handling XHTML "hidden" form inputs
* *
* @property bool $renderValueAsInput Render the hidden input, even when in renderValue mode (default=false)
*
*/ */
class InputfieldHidden extends Inputfield { class InputfieldHidden extends Inputfield {
@@ -18,6 +20,7 @@ class InputfieldHidden extends Inputfield {
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
$this->setAttribute('type', 'hidden'); $this->setAttribute('type', 'hidden');
$this->set('renderValueAsInput', false);
$this->initValue = ''; $this->initValue = '';
} }
@@ -25,6 +28,14 @@ class InputfieldHidden extends Inputfield {
return "<input " . $this->getAttributesString() . " />"; return "<input " . $this->getAttributesString() . " />";
} }
public function ___renderValue() {
if($this->renderValueAsInput) {
return $this->render();
} else {
return parent::___renderValue();
}
}
public function getAttributes() { public function getAttributes() {
$attrs = parent::getAttributes(); $attrs = parent::getAttributes();
if(!strlen($attrs['value']) && $this->initValue) $attrs['value'] = $this->initValue; if(!strlen($attrs['value']) && $this->initValue) $attrs['value'] = $this->initValue;