__('Checkboxes', __FILE__), // Module Title 'summary' => __('Multiple checkbox toggles', __FILE__), // Module Summary 'version' => 100, 'permanent' => true, ); } public function init() { $this->set('table', false); $this->set('thead', ''); $this->set('optionColumns', 0); parent::init(); $this->set('size', null); // cancel 'size' attribute used by select multiple } public function ___render() { $this->checkDefaultValue(); $out = ''; $table = null; $columns = (int) $this->optionColumns; $inline = $columns === 1 || $columns > 10; $liAttr = ''; $ulClass = ''; if($this->table) { $table = $this->modules->get("MarkupAdminDataTable"); $table->setEncodeEntities(false); if($this->thead) $table->headerRow(explode('|', htmlspecialchars($this->thead, ENT_QUOTES, 'UTF-8'))); } else if($columns) { if($inline) { $ulClass = 'InputfieldCheckboxesFloated'; } else { $liWidth = round(100 / $columns)-1; // 1% padding-right added from stylesheet $liAttr = " style='width: {$liWidth}%;'"; $ulClass = 'InputfieldCheckboxesColumns'; } $ulClass .= " ui-helper-clearfix"; } else { $ulClass = 'InputfieldCheckboxesStacked'; } if(!$table) $out = "\n"; return $out; } public function set($key, $value) { if($key == 'optionColumns') { $value = (int) $value; if($value < 0) $value = 0; if($value > 10) $value = 10; } return parent::set($key, $value); } public function ___getConfigInputfields() { $inputfields = parent::___getConfigInputfields(); $f = wire('modules')->get('InputfieldInteger'); $f->label = $this->_('Columns of Checkboxes'); $f->description = $this->_('If you want the checkboxes to display in columns (rather than stacked), enter the number of columns you want to use (up to 10). To display checkboxes side-by-side (inline) enter 1.'); $f->attr('name', 'optionColumns'); $f->attr('value', (int) $this->optionColumns); $inputfields->add($f); return $inputfields; } }