Magento 2 – Set Default Value in Yes/No Field of Widget.xml

magento2widget

I am creating custom widget in Magento 2. I have created widget.xml file to create this. All things are fine and widget option is showing as well in admin.

Only I want selected value "Yes" instead of "No". Right now it is "No" as default selected value.

Here is the code I am using for select box in widget.xml

<parameter name="chart_layout" xsi:type="select" visible="true" source_model="Magento\Config\Model\Config\Source\Yesno" sort_order="2">
   <label translate="true">Full Width</label>
</parameter>

I am getting below section as screenshot.

enter image description here

Best Answer

If default values are not working for YesNo (I don't have time to dig) then you could always cheese the system for the time being and try to find a cleaner solution:

<parameter name="chart_layout" xsi:type="select" visible="true">
    <label translate="true">Full Width</label>
    <options>
        <option name="yes" value="1" selected="true">
            <label translate="true">Yes</label>
        </option>
        <option name="no" value="0">
            <label translate="true">No</label>
        </option>
    </options>
</parameter>
Related Topic