1

I have a UI component Form checkbox. I want it to default to yes rather than no.

This is my Field

<field name="status">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/form/element/single-checkbox-toggle-notice</item>
                <item name="dataType" xsi:type="string">boolean</item>
                <item name="formElement" xsi:type="string">checkbox</item>
                <item name="source" xsi:type="string">template</item>
                <item name="prefer" xsi:type="string">toggle</item>
                <item name="valueMap" xsi:type="array">
                    <item name="true" xsi:type="number">1</item>
                    <item name="false" xsi:type="number">0</item>
                </item>
                <item name="default" xsi:type="number">0</item>
                <item name="label" xsi:type="string" translate="true">Please confirm you wish to proceed ?</item>
            </item>
        </argument>

3 Answers 3

0

You need to create default a configuration for your admin items in

app/code/VendorName/MyModule/etc/config.xml

<default>
<section>
   <group>
       <field>{value}</field>
   </group>
</section>
</default>

For example:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
       <default>
           <section_id>
               <group_id>
                   <my_boolean_option>1</my_boolean_option>
               </group_id>
           </section_id>
       </default>
    </config>
0

Try this

    <field name="status">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="sortOrder" xsi:type="number">10</item>
                <item name="dataType" xsi:type="string">boolean</item>
                <item name="formElement" xsi:type="string">checkbox</item>
                <item name="prefer" xsi:type="string">toggle</item>
                <item name="label" xsi:type="string" translate="true">Please confirm you wish to proceed ?</item>
                <item name="valueMap" xsi:type="array">
                    <item name="true" xsi:type="number">1</item>
                    <item name="false" xsi:type="number">0</item>
                </item>
                <item name="valuesForOptions" xsi:type="array">
                    <item name="boolean" xsi:type="string">boolean</item>
                </item>
                <item name="default" xsi:type="number">1</item>
                <item name="dataScope" xsi:type="string">status</item>
            </item>
        </argument>
    </field>
0

Try this

  <field name="status" formElement="checkbox">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="source" xsi:type="string">sales_rule</item>
            </item>
        </argument>
        <settings>
            <dataType>boolean</dataType>
            <label translate="true">Status</label>
            <dataScope>status</dataScope>
        </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>

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.