0

I want to create Yes/No flag attribute in category admin panel.

Data patch is already created and in category_form.xml i am trying different solutions.

<fieldset name="general">
        <field name="enable_slider">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="required" xsi:type="boolean">false</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">false</item>
                    </item>
                    <item name="sortOrder" xsi:type="number">333</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="label" xsi:type="string" translate="true">Enable Slider</item>
                </item>
            </argument>
        </field>
</fieldset>```

2 Answers 2

1

Try this

<fieldset>
    <field name="enable_slider" component="Magento_Ui/js/form/element/single-checkbox-toggle-notice" formElement="checkbox">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="default" xsi:type="number">0</item>
            </item>
        </argument>
        <settings>
            <dataType>boolean</dataType>
            <label translate="true">Enable Slider</label>
        </settings>
        <formElements>
            <checkbox>
                <settings>
                    <valueMap>
                        <map name="false" xsi:type="number">0</map>
                        <map name="true" xsi:type="number">1</map>
                    </valueMap>
                    <prefer>toggle</prefer>
                </settings>
            </checkbox>
        </formElements>
    </field>
</fieldset>

Source: Adobe DevDocs

0

I have used below code to complete my requirement and it's working fine.

<fieldset name="general">
    <field name="enable_slider">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">boolean</item>
                <item name="formElement" xsi:type="string">checkbox</item>
                <item name="label" xsi:type="string" translate="true">Enable Slider</item>
                <item name="prefer" xsi:type="string">toggle</item>
                <item name="valueMap" xsi:type="array">
                    <item name="true" xsi:type="string">1</item>
                    <item name="false" xsi:type="string">0</item>
                </item>
                <item name="default" xsi:type="number">0</item>
            </item>
        </argument>
    </field>
</fieldset>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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