Switch - Option type W (checkbox)

Implement Swicthes

W loads the native switch support. A switch in an ordinary form saves with that form; use the LIVE switch configuration only for immediate native saving.

addField([
    'type'=>'switch', 'name'=>'VISIBLE', 'id'=>'item_visible',
    'label'=>'Visible', 'value'=>$currentVisible,
    'onValue'=>'1', 'offValue'=>'0',
    'class'=>'', 'switch_class'=>'',
    'attributes'=>'', 'switch_attributes'=>''
]);

The default values are1 and0. An omitted id uses name. class/attributes apply to the hidden input; switch_class/switch_attributes apply to its control. style, blockClass and blockStyle customize native presentation. readonly makes the control static, but is not server authorization.

$('#item_visible').on('change', function () {
    const value = $(this).val();
});
turn_switch($('#switch_item_visible'), 'OFF', '0');

Use the real hash-prefixed selector. turn_switch queues change/keyup triggers on the associated input. For an ordinary form, persistence still waits for form submission.

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.

For a read-only boolean result in a Table View, use the native status field instead of an editable switch.