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

asked Dec 6, 2016 at 9:59

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.