InputfieldRadios
Radio button group for single-item selection
Extends [[InputfieldSelect]] — all
option management methods (addOption(), addOptions(), setOptions(),
addOptionsString(), etc.) are inherited and documented there.
$f = $modules->get('InputfieldRadios');
$f->name = 'size';
$f->label = 'T-shirt size';
$f->addOptions(['s' => 'Small', 'm' => 'Medium', 'l' => 'Large', 'xl' => 'XL']);
$f->val('m'); // pre-select Medium
$form->add($f); See [[Inputfield]] for the shared Inputfield API (labels, collapsed states, showIf, rendering, processing, etc.).
| Property | Type | Default | Description |
|---|---|---|---|
optionColumns | int | 0 | Layout columns: 0=stacked, 1=inline, 2–10=N columns (see Layout below) |
optionWidth | string | '' | Fixed CSS width per option, e.g. '150px' or '10em' 3.0.184+ |
By default, radio buttons render as a stacked vertical list. The layout can be
changed with optionColumns or optionWidth. These work identically to the same
properties in [[InputfieldCheckboxes]].
$f->optionColumns = 0; // default: stacked vertical list
$f->optionColumns = 1; // inline: options flow side-by-side
$f->optionColumns = 3; // 3 equal-width percentage columns (values 2–10 supported)
$f->optionWidth = '150px'; // fixed-width columns, wraps responsively
$f->optionWidth = '1'; // auto-calculate width from longest labelWhen both optionColumns and optionWidth are set, optionWidth takes precedence.
Two rendering behaviors can be changed globally via $config->Inputfield
(typically set in config.php):
$config->InputfieldRadios = [
'wbr' => true, // insert <wbr> tags in labels for long-word breaking
'noSelectLabels' => false, // allow text selection on radio labels (default: true = no selection)
]; - Returns a single value (string), not an array. Use
$f->val()to get or set. - Optgroups are not supported.
- Source file:
wire/modules/Inputfield/InputfieldRadios/Inputfield Radios.module
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Inputfield class also inherits all the methods and properties of: InputfieldSelect, Inputfield, WireData and Wire.
Common
Properties
| Name | Return | Summary | |
|---|---|---|---|
| Inputfield | int | Number of columns to display radios in, or 0 for vertical stacked, or 1 for inline DEFAULT: 0 | |
| Inputfield | string | Alternative to optionColumns, specify option width like '222px', '22em', etc. or '1' for auto. 3.0.184+ DEFAULT: blank |
Additional methods and properties
In addition to the methods and properties above, Inputfield
API reference based on ProcessWire core version 3.0.267