InputfieldToggle class
A toggle providing similar input capability to a checkbox but much more configurable.
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 Inputfield
class also inherits all the methods and properties of: Inputfield, WireData and Wire.
Common
Properties
Name | Return | Summary | Default |
---|---|---|---|
Inputfield | string | Default selected value of 'no', 'yes', 'other' or 'none' | none |
Inputfield | string | Inputfield class to use or blank for this toggle buttons | blank |
Inputfield | int | Label type to use: 0=yes/no, 1=true/false, 2=on/off, 3=enabled/disabled, 100=custom | 0 |
Inputfield | string | Custom no/off label | ✗ |
Inputfield | string | Custom label for optional other value Label to use for "other" option | ? |
Inputfield | bool int | Allow radios or toggles to be de-selected, enabling possibility of no-selection? | false |
Inputfield | int bool | Use the "other" option? | false |
Inputfield | int bool | Reverse the order of the Yes/No options? | false |
Inputfield | bool int | Use vertically oriented radio buttons? Applies only if $inputfieldClass is 'InputfieldRadios' | false |
Inputfield | int string | Integer value when selection is made or blank string when no selection (0=No, 1=Yes, 2=Other, ''=Unknown) | |
Inputfield | string | Custom yes/on label | ✓ |
Additional methods and properties
In addition to the methods and properties above, Inputfield
API reference based on ProcessWire core version 3.0.251