Skip to main content
Version: 1.24.0

Switch

Overview

The Switch component allows the user to toggle between two states.


Specification

Property

Here is a list of properties that can be used for modifying the component:

NameTypeDefaultDescriptionRemark
checkedTextstring""Text to be displayed when the component state is "checked"
classNamestring""Component class name
idstring""Component id name
labelstring""Label for the componentLabel will not be displayed if unspecified or left empty
labelPlacementstring"left"The position where the label is displayedAvailable options: top, left, right, bottom
unCheckedTextstring""Text to be displayed when the component state is "unchecked"
checkedbooleanfalseCheck/Uncheck the component
disabledbooleanfalseEnable/Disable the component
visiblebooleantrueShow/Hide the component

Event

Here is a list of events that can be specified:

NameTypeDescriptionRemark
changefunctionEvent handler when the checked state has been changedIt will pass the event object as the argument

You can receive the following values in event.detail
event.detail.checked : Checked state after the change

Constructor

Switch(options)
Here is a list of available constructors:

Parameter

NameTypeDefaultDescriptionRemark
optionsobject{}Object that includes component properties

Sample Code

tip

Please check the package installation method first.

Here is a sample code when all parameters are specified:

const Kuc = Kucs['1.x.x'];

const space = kintone.app.record.getSpaceElement('space');

const kucSwitch = new Kuc.Switch({
label: 'Switch',
labelPlacement: 'left',
checkedText: 'ON',
unCheckedText: 'OFF',
checked: false,
className: 'options-class',
id: 'options-id',
visible: true,
disabled: false
});
space.appendChild(kucSwitch);

kucSwitch.addEventListener('change', event => {
console.log(event);
});