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.).

Properties
PropertyTypeDefaultDescription
optionColumnsint0Layout columns: 0=stacked, 1=inline, 210=N columns (see Layout below)
optionWidthstring''Fixed CSS width per option, e.g. '150px' or '10em' 3.0.184+
Layout

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 label

When both optionColumns and optionWidth are set, optionWidth takes precedence.

Global config

Two rendering behaviors can be changed globally via $config->InputfieldRadios (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)
];
Notes
  • 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/InputfieldRadios.module
API reference: methods, properties, hooks

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the InputfieldRadios class also inherits all the methods and properties of: InputfieldSelect, Inputfield, WireData and Wire.

Show class? Show args? Only hookable?

Properties

NameReturnSummary
InputfieldRadios::optionColumns int Number of columns to display radios in, or 0 for vertical stacked, or 1 for inline
DEFAULT: 0
InputfieldRadios::optionWidth 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, InputfieldRadios also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.267

AltStyle によって変換されたページ (->オリジナル) /