Skip to main content

Toggle

Toggle fieldToggle field

An inline switch that flips between exactly two labeled values. It collects the selected option value (a string). It's always in one of its two states, so it always returns a value.

$p->toggle('ripeness', 'Ripeness')
->options([
'ripe' => 'Ripe', // value => label
'unripe' => 'Unripe',
])
->default('ripe'); // Which value starts selected (defaults to the first).

Runnable script: playground/02-fields-toggle.php.

Options

NameDescriptionRequiredDefault
options()The two values to switch between, as a value => label map. A third is a build-time error.Yes-
default()Which value starts selected; a literal that is neither of the two is a build-time error.NoFirst option

Keyboard

KeyAction
/ / Space / / Flip to the other value
a letterJump to the value whose label starts with it
EnterAccept the current value
EscCancel

Display modes

In all four display modes - Unicode or ASCII, color on or off:

ANSINo ANSI
UnicodeToggle: Unicode + ANSIToggle: Unicode + ANSIToggle: Unicode + No ANSIToggle: Unicode + No ANSI
ASCIIToggle: ASCII + ANSIToggle: ASCII + ANSIToggle: ASCII + No ANSIToggle: ASCII + No ANSI