__('Radio Buttons', __FILE__), // Module Title
'summary' => __('Radio buttons for selection of a single item', __FILE__), // Module Summary
'version' => 102,
'permanent' => true,
);
}
public function init() {
$this->set('optionColumns', 0);
parent::init();
}
public function ___render() {
$this->checkDefaultValue();
$inline = false;
$columns = (int) $this->optionColumns;
if($columns === 1) $inline = true;
$options = $this->getOptions();
$liAttr = '';
if($columns) {
if(count($options) >= $columns && !$inline) {
$liWidth = round(100 / $columns)-1; // 1% padding-right added from stylesheet
$liAttr = " style='width: {$liWidth}%;'";
$ulClass = 'InputfieldRadiosColumns';
} else {
// don't bother setting a width, we will let them float where they want instead
$ulClass = 'InputfieldRadiosFloated';
}
$out = "\n\t
";
} else {
$out = "\n\t";
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 Radio Buttons');
$f->description = $this->_('If you want the radio buttons to display in columns (rather than stacked), enter the number of columns you want to use (up to 10). To display buttons side-by-side (inline) enter 1.');
$f->notes = $this->_('If no number is specified here, then each radio button will display on its own line.');
$f->attr('name', 'optionColumns');
$f->attr('value', (int) $this->optionColumns);
$inputfields->add($f);
return $inputfields;
}
}