From 6871035292dac89c5c6021c9477417c29746eb45 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 19 Aug 2021 12:49:12 -0400 Subject: [PATCH] Upgrade InputfieldRadios and InputfieldCheckboxes to support a 'optionWidth' configuration property per processwire/processwire-issues#1327 --- .../InputfieldCheckboxes.css | 7 ++ .../InputfieldCheckboxes.module | 102 +++++++++++++++--- .../InputfieldRadios/InputfieldRadios.css | 5 + .../InputfieldRadios/InputfieldRadios.module | 55 +++++++--- 4 files changed, 138 insertions(+), 31 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldCheckboxes/InputfieldCheckboxes.css b/wire/modules/Inputfield/InputfieldCheckboxes/InputfieldCheckboxes.css index 75794373..31197282 100644 --- a/wire/modules/Inputfield/InputfieldCheckboxes/InputfieldCheckboxes.css +++ b/wire/modules/Inputfield/InputfieldCheckboxes/InputfieldCheckboxes.css @@ -49,6 +49,13 @@ padding-bottom: 1%; } +.Inputfields .InputfieldCheckboxesWidth li { + display: inline-block; +} +.Inputfields .InputfieldCheckboxesWidth li label { + white-space: initial; +} + .InputfieldCheckboxes table label { white-space: nowrap; } diff --git a/wire/modules/Inputfield/InputfieldCheckboxes/InputfieldCheckboxes.module b/wire/modules/Inputfield/InputfieldCheckboxes/InputfieldCheckboxes.module index f2904fb5..97c8f4a2 100644 --- a/wire/modules/Inputfield/InputfieldCheckboxes/InputfieldCheckboxes.module +++ b/wire/modules/Inputfield/InputfieldCheckboxes/InputfieldCheckboxes.module @@ -1,11 +1,15 @@ __('Checkboxes', __FILE__), // Module Title 'summary' => __('Multiple checkbox toggles', __FILE__), // Module Summary - 'version' => 107, + 'version' => 108, 'permanent' => true, - ); + ); } + /** + * Init + * + */ public function init() { $this->set('table', false); $this->set('thead', ''); $this->set('optionColumns', 0); + $this->set('optionWidth', ''); parent::init(); $this->set('size', null); // cancel 'size' attribute used by select multiple } + /** + * Render + * + * @return string + * + */ public function ___render() { + + $sanitizer = $this->wire()->sanitizer; $this->checkDefaultValue(); $out = ''; @@ -37,16 +54,22 @@ class InputfieldCheckboxes extends InputfieldSelectMultiple implements Inputfiel $inline = $columns === 1 || $columns > 10; $liAttr = ''; $ulClass = ''; - $inputClass = $this->wire('sanitizer')->entities($this->attr('class')); + $inputClass = $sanitizer->entities($this->attr('class')); $entityEncode = $this->getSetting('entityEncodeText') === false ? false : true; - + $options = $this->getOptions(); + $optionWidth = $this->optionWidth ? $this->getOptionWidthCSS($this->optionWidth, $options) : ''; + if($this->table) { /** @var MarkupAdminDataTable $table */ - $table = $this->modules->get("MarkupAdminDataTable"); + $table = $this->modules->get("MarkupAdminDataTable"); $table->setEncodeEntities(false); $table->setSortable(false); $table->addClass('pw-no-select'); - if($this->thead) $table->headerRow(explode('|', htmlspecialchars($this->thead, ENT_QUOTES, 'UTF-8'))); + if($this->thead) $table->headerRow(explode('|', htmlspecialchars($this->thead, ENT_QUOTES, 'UTF-8'))); + + } else if($optionWidth) { + $liAttr = " style='width:$optionWidth'"; + $ulClass = 'InputfieldCheckboxesWidth'; } else if($columns) { @@ -67,12 +90,12 @@ class InputfieldCheckboxes extends InputfieldSelectMultiple implements Inputfiel if(!$table) $out = "