A Form View LIVE switch uses native L and W support, an authorized existing row and the owning dbtable/idfield/idvalue. Reuse native asset loading and db_actions rather than inserting a versioned script URL or a separate save endpoint.
addField([
'type'=>'live', 'inputType'=>'switch',
'name'=>'VISIBLE', 'id'=>'item_visible', 'label'=>'Visible',
'value'=>$currentVisible, 'onValue'=>'1', 'offValue'=>'0',
'encdata'=>[
'TYPE'=>'LIVE', 'DBTABLE'=>$dbtable,
'IDFIELD'=>$idfield, 'IDVALUE'=>$idvalue
]
]);
Use the actual column/current value and authorize the row on the server. class/attributes apply to the input; switch_class/switch_attributes apply to its switch control. readonly produces a static control, but does not replace server-side write protection. Omitted encdata uses the owning native page variables.
$('#item_visible').on('change', function () {
const value = $(this).val();
});
turn_switch($('#switch_item_visible'), 'ON', '1');
turn_switch expects the switch element, an ON/OFF label and the stored value. It queues the native change/keyup triggers; it is not a separate persistence API. See Switch for an ordinary submitted form.
Full arrays are the modern extensible configuration. Strings remain supported legacy shorthand/quick syntax. Prefer full arrays for new definitions; use only keys supported by the owning field or component.