1

https://devdocs.magento.com/guides/v2.3/ui_comp_guide/components/ui-checkbox.html

devdocs says default value is false but there is no clue how to turn it to true. Anyone know what to add in xml file to make it happen. Many thanks

0

You can use the following code to set the default checkbox value in ui_component

<form>
<fieldset>
    <field name="myCheckbox" formElement="checkbox">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="default" xsi:type="boolean">true</item>
            </item>
        </argument>
        <settings>
            <label translate="true">Enabled</label>
            <tooltip>
                <description translate="true">This is my checkbox's description</description>
            </tooltip>
        </settings>
        <formElements>
            <checkbox>
                <settings>
                    <prefer>toggle</prefer>
                    <valueMap>
                        <map name="false" xsi:type="boolean">false</map>
                        <map name="true" xsi:type="boolean">true</map>
                    </valueMap>
                </settings>
            </checkbox>
        </formElements>
    </field>
</fieldset>

Let me know if you have any other issue with the code Thanks

3
  • I've tried <item name="default" xsi:type="number">true</item> but it doesn't get it checked. – Long Nguyen May 5 '20 at 10:29
  • <item name="default" xsi:type="boolean">true</item> works. Edit your answer and I'll accept it. – Long Nguyen May 5 '20 at 10:31
  • @LongNguyen... Yes, you are right and I've updated my answer Thanks – Shankar May 6 '20 at 11:09

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.