In order for to use the switch option type (W) is required .
The following settings are available, but mostly optional:
$field=[ 'type' => 'switch', //required 'name' => 'VISIBLE', //column name, required 'label' => 'VISIBLE' , // required 'id' => 'VISIBLE', //optional, if not provided name is used as id 'value' => $db_items->result(0,'VISIBLE'), //optional, if not provided the value of name from the DB is fetched 'onValue'=> '1', //optional, if not provided 1 is default 'offValue'=> '0', //optional, if not provided 0 is default 'class' => '', //optional, applied to hidden input 'switch_class' => '', //optional, applied to the switch div 'attributes' => 'readonly' //optional, used in the hidden input, readonly makes a static switch 'switch_attributes' => '' //optional, applied to the switch div, great for adding data attributes and maniuplate switch states ]; addField($field);
NOTE: if the attribute readonly exists, the switch is blocked
A switch can have the following minimum settings:
addField([ 'type' => 'switch', //required 'name' => 'VISIBLE', //column name, required 'label' => 'VISIBLE' , // required 'value' => $db_items->result(0,'VISIBLE') ]);
Using JS / JQuery, a switch toggle can be detected by checking the change trigger of the ID of the swicth:
$('#VISIBLE').on('change', function(){ var val = $(this).val(); alert("The Switch was clicked, value: "+val); });
To modify the state of a switch using Java Script, use the turn_switch( ) function, keep note that the system adds "switch_" to the ID of the filed, so for example a VISIBLE field would need '#switch_VISIBLE' as the ID selector
turn_switch($("switch_VISIBLE"),"ON / OFF", "1 / 0 , true / false , yes / no, etc");