You can Manage/Add the checkbox component field in the admin panel Ui Component Form Magento. You can add a Checkbox type field with toggle, radio, and regular checkbox options.
Use formElement as a checkbox in the XML file with a field tag. <field name=”my_field” sortOrder=”10″ formElement=”checkbox”>
Add below XML code snippet for the checkbox component in a custom form XML file to show the toggle,
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Rakesh Jesadiya
* Category Page add checkbox field...
*/
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="general" sortOrder="5">
<field name="is_active" sortOrder="10" formElement="checkbox">
<settings>
<validation>
<rule name="required-entry" xsi:type="boolean">false</rule>
</validation>
<dataType>boolean</dataType>
<label translate="true">Enable Page</label>
</settings>
<formElements>
<checkbox>
<settings>
<valueMap>
<map name="false" xsi:type="string">0</map>
<map name="true" xsi:type="string">1</map>
</valueMap>
<prefer>toggle</prefer>
</settings>
</checkbox>
</formElements>
</field>
</fieldset>
</form>
If you want to show the checkbox as a toggle, use node,
<prefer>toggle</prefer>
You can display the checkbox as a radio option using,
<prefer>radio</prefer> in <formElements><settings /> node.
If you want to display a regular checkbox field, you don’t need to write <prefer> node in <formElements><settings />.
The default value is the regular checkbox icon for the checkbox field.
