Arguments
Name | Type | Default | Description |
---|
id | string | | A unique ID. This ID will be used to get the value |
type | string | switcher | Type of field |
title | string | | Title of the field |
default | string | | Default value from database, if the option doesn’t exist |
subtitle | string | | Subtitle to display below the title |
desc | string | | Description to display after the field |
help | string | | Text to display on right-corner (as hover/popup) the field |
class | string | | Extra CSS classes (space separated) to append to the field |
before | string | | Content to display before the field |
after | string | | Content to display after the field |
dependency | array | | Define field visibility depending on other field value |
attributes | array | | Extra HTML attributes to append to the field |
sanitize | string | | Callback function for sanitizing value |
validate | string | | Callback function for validating value |
EXTRAS | | | |
text_on | string | ON | Text to display on the “ON” label |
text_off | string | OFF | Text to display on the “OFF” label |
text_width | number | 60 | The width of the switcher |
label | string | | The text to display along with the switcher |
Simple Switcher Field Example
array(
'id' => 'example-switcher',
'type' => 'switcher',
'title' => 'Example Switcher',
),
Switcher Field Example with Label
array(
'id' => 'example-switcher',
'type' => 'switcher',
'title' => 'Example Switcher',
'label' => 'Do you want to activate the switch?',
'default' => true,
),
Switcher Field Example with Dependency
array(
'id' => 'example-switcher',
'type' => 'switcher',
'title' => 'Example Switcher',
'default' => true,
),
//Text field dependent of the above switcher
array(
'id' => 'example-text',
'type' => 'text',
'title' => 'Text',
'dependency' => array('example-switcher', '==', 'true'),
),
Switcher Field Example with Custom Text
array(
'id' => 'example-switcher',
'type' => 'switcher',
'title' => 'Switcher with Yes/No',
'text_on' => 'Yes',
'text_off' => 'No',
),
array(
'id' => 'example-switcher-2',
'type' => 'switcher',
'title' => 'Switcher with Enabled/Disabled',
'text_on' => 'Enabled',
'text_off' => 'Disabled',
'text_width' => 100,
),