mirror of
https://github.com/processwire/processwire.git
synced 2025-08-16 19:54:24 +02:00
Add option to InputfieldCheckbox to enable it to render without labels (useful for when rendered as in first/last table column or similar situations)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* @property string $uncheckedValue
|
||||
* @property string $label2 Alterate label to display next to checkbox (default=use regular label)
|
||||
* @property string $checkboxLabel Same as label2, but used as part of field config rather than API-only config.
|
||||
* @property bool $checkboxOnly Show only the checkbox without label text next to it? (default=false) @since 3.0.144
|
||||
* @property array $labelAttrs Optional attributes for <label> element that surrounds checkbox (default=[]) @since 3.0.141
|
||||
* @property int $autocheck When set to 1, setting value attribute to non-blank/non-zero automatically triggers checked.
|
||||
*
|
||||
@@ -20,7 +21,7 @@ class InputfieldCheckbox extends Inputfield {
|
||||
return array(
|
||||
'title' => __('Checkbox', __FILE__), // Module Title
|
||||
'summary' => __('Single checkbox toggle', __FILE__), // Module Summary
|
||||
'version' => 105,
|
||||
'version' => 106,
|
||||
'permanent' => true,
|
||||
);
|
||||
}
|
||||
@@ -48,6 +49,7 @@ class InputfieldCheckbox extends Inputfield {
|
||||
|
||||
// alternate label for checkbox (both do the same thing but for different config context)
|
||||
$this->set('label2', ''); // typically specified by API
|
||||
$this->set('checkboxOnly', false); // render checkbox only, without showing label text
|
||||
$this->set('checkboxLabel', ''); // typically specified by interactive config
|
||||
$this->set('labelAttrs', array()); // Optional attributes for <label> element that surrounds checkbox (3.0.141+)
|
||||
|
||||
@@ -79,20 +81,23 @@ class InputfieldCheckbox extends Inputfield {
|
||||
$label = '';
|
||||
$user = $this->wire('user');
|
||||
|
||||
if($user->language) $label = $this->getSetting("checkboxLabel$user->language");
|
||||
if(!$label) $label = $this->getSetting("checkboxLabel");
|
||||
if(!$label && $this->checkedValueIsLabel) $label = $this->checkedValue;
|
||||
if(!$label) $label = $this->getSetting('label2');
|
||||
if(!$this->checkboxOnly) {
|
||||
if($user->language) $label = $this->getSetting("checkboxLabel$user->language");
|
||||
if(!$label) $label = $this->getSetting("checkboxLabel");
|
||||
if(!$label && $this->checkedValueIsLabel) $label = $this->checkedValue;
|
||||
if(!$label) $label = $this->getSetting('label2');
|
||||
$label = trim($label);
|
||||
}
|
||||
|
||||
$this->set('skipLabel', $this->description || $label ? Inputfield::skipLabelFor : Inputfield::skipLabelHeader);
|
||||
if(!$label) $label = $this->label;
|
||||
if(!$label && !$this->checkboxOnly) $label = $this->label;
|
||||
|
||||
// TBA: if($this->uncheckedValue) return $this->renderRadio();
|
||||
|
||||
$attrs = $this->getAttributes();
|
||||
$attrs['value'] = $this->checkedValue;
|
||||
|
||||
if($this->getSetting('entityEncodeLabel') !== false) {
|
||||
if(strlen($label) && $this->getSetting('entityEncodeLabel') !== false) {
|
||||
$label = $this->entityEncode($label, Inputfield::textFormatBasic);
|
||||
}
|
||||
|
||||
@@ -103,9 +108,9 @@ class InputfieldCheckbox extends Inputfield {
|
||||
$labelAttrs = '';
|
||||
}
|
||||
|
||||
$out =
|
||||
"<label$labelAttrs><input type='checkbox' " . $this->getAttributesString($attrs) . " />" .
|
||||
"<span class='pw-no-select'>$label</span></label>";
|
||||
$out = "<label$labelAttrs><input type='checkbox' " . $this->getAttributesString($attrs) . " />";
|
||||
if(strlen($label)) $out .= "<span class='pw-no-select'>$label</span>";
|
||||
$out .= "</label>";
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
Reference in New Issue
Block a user