I've created a custom module in which I've a drop down field having "Yes/No" value, here is the screenshot:


I just want to replace this drop down into switch ,just like below screenshot:


How can I achieve the same?

I've created module from "Silksoftware" and to creating the form fields it's using block just like:

                'label' => __('Available Every Week'),
                'title' => __('Available Every Week'),
                'name' => 'available_every_week',

                'options' => \Namespace\Test\Block\Adminhtml\Gametype\Grid::getOptionArray5(),
                'disabled' => $isElementDisabled



is returning values(Yes/No) for the dropdown.

Waiting for the update.

  • thanks for the reply,this doesn't work getting " Class boolean does not exist" problem. nimb.ws/DEUX8o – wakar Ahamad Feb 15 '19 at 13:06

You need to create your form using UI component library provided in magento 2.

Use below example:

<field name="available_every_week" formElement="checkbox">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="source" xsi:type="string">category</item>
            <item name="default" xsi:type="number">1</item>
            <rule name="required-entry" xsi:type="boolean">false</rule>
        <label translate="true">Available Every Week</label>
                    <map name="false" xsi:type="string">0</map>
                    <map name="true" xsi:type="string">1</map>
| improve this answer | |
  • thanks for the reply! I've created from Silksoftware,which is creating form just like Magento 1 way.is this possible to add switch in this? – wakar Ahamad Feb 15 '19 at 13:08
  • No, it is not possible without UI component form. – Nikunj Rathod Feb 15 '19 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.