6

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

1 Answer 1

11

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>
2
  • Not working, I get following error: Element 'parameter', attribute 'value': The attribute 'value' is not allowed Dec 6, 2016 at 10:32
  • I've changed the answer to allow for a temporary fix. Dec 6, 2016 at 10:42

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.