InputfieldToggle class - ProcessWire API

An Inputfield for handling an on/off toggle that maintains a boolean value (or null when no selection). This provides an alternative to a single checkbox field.

API usage example

// Default behavior displays toggle of "Yes" and "No":
$f = $modules->get('InputfieldToggle');
$f->attr('name', 'test_toggle_field');
$f->label = 'Do you like toggle fields?';

// Optionally make it show "On" and "Off" (rather than "Yes" and "No"):
$f->labelType = InputfieldToggle::labelTypeOn;

// Optionally set custom labels:
$f->labelType = InputfieldToggle::labelTypeCustom;
$f->yesLabel = 'Yes please';
$f->noLabel = 'No thanks';

// Optionally add an "other" option with label "Not sure":
$f->useOther = true;
$f->otherLabel = 'Not sure';

// Set the value: 0=No, 1=Yes, 2=Other, or blank string '' for no selection (Unknown)
$f->val(1);

// Optionally set to use radio buttons rather than toggle buttons:
$f->inputfieldClass = 'InputfieldRadios';

// Remember to add to your InputfieldForm, InputfieldWrapper or InputfieldFieldset:
$form->add($f);
echo $form->render();

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

Properties

NameReturnSummary 
InputfieldToggle::defaultOption string Default selected value of 'no', 'yes', 'other' or 'none'
DEFAULT: none
 
InputfieldToggle::inputfieldClass string Inputfield class to use or blank for this toggle buttons
DEFAULT: blank
 
InputfieldToggle::labelType int Label type to use: 0=yes/no, 1=true/false, 2=on/off, 3=enabled/disabled, 100=custom
DEFAULT: 0
 
InputfieldToggle::noLabel string Custom no/off label
DEFAULT:
 
InputfieldToggle::otherLabel string Custom label for optional other value Label to use for "other" option
DEFAULT: ?
 
InputfieldToggle::useDeselect bool int Allow radios or toggles to be de-selected, enabling possibility of no-selection?
DEFAULT: false
 
InputfieldToggle::useOther int bool Use the "other" option?
DEFAULT: false
 
InputfieldToggle::useReverse int bool Reverse the order of the Yes/No options?
DEFAULT: false
 
InputfieldToggle::useVertical bool int Use vertically oriented radio buttons? Applies only if $inputfieldClass is 'InputfieldRadios'
DEFAULT: false
 
InputfieldToggle::value int string Integer value when selection is made or blank string when no selection (0=No, 1=Yes, 2=Other, ''=Unknown) 
InputfieldToggle::yesLabel string Custom yes/on label
DEFAULT:
 

Additional methods and properties

In addition to the methods and properties above, InputfieldToggle also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.255