8

I am trying to find out how I can create a select box in magento component ui form and point it to some where I can fill in the select list.

Something like this I thought would work but it does not

<field name="formats">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">text</item>
                <item name="disabled" xsi:type="boolean">false</item>
                <item name="label" xsi:type="string" translate="true">formats</item>
                <item name="formElement" xsi:type="string">select</item>
                <item name="enabled" xsi:type="boolean">false</item>
                <item name="source" xsi:type="string">Magento\Catalog\Model\Product\AttributeSet\Options</item>
                <item name="dataScope" xsi:type="string">formats</item>
            </item>
        </argument>
    </field>

Thanks

2 Answers 2

21

You can add like this

<field name="formats">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Magento\Catalog\Model\Product\AttributeSet\Options</item>
        <item name="config" xsi:type="array">
            <item name="dataType" xsi:type="string">text</item>
            <item name="label" xsi:type="string" translate="true">Formats</item>
            <item name="formElement" xsi:type="string">select</item>
            <item name="source" xsi:type="string">modulename</item>
            <item name="dataScope" xsi:type="string">formats</item>
            <item name="default" xsi:type="string">0</item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
            </item>
        </item>
    </argument>
</field>
8
  • Genius! May I ask where you got this information from for future reference?
    – stewrat
    Commented Oct 27, 2016 at 5:44
  • You are at right place bro. Just keep searching :)
    – Priyank
    Commented Oct 27, 2016 at 5:47
  • @Priyank where is the modulename from <item name="source" /> defined ? I tried mine from module.xml, routes.xml but this doesn't work. I do receive this error message: prntscr.com/d9c73e Commented Nov 19, 2016 at 19:35
  • @Vasilii if your modulename is the name of your module you created . For eg if in for module Magento_Catalog the catalog is the modulename.
    – Priyank
    Commented Nov 20, 2016 at 2:40
  • @Priyank it doesn't work in the way you described. I wonder if source make a reference to a module model or other .php file that contain select options. P.S. I try this with multiselect type for formElement. Commented Nov 22, 2016 at 18:47
5

This is an approach that is more common at least as of Magento 2.3:

<field name="image_overlay_art" sortOrder="40" formElement="select">
    <settings>
        <dataType>int</dataType>
        <label translate="true">Show Art on Image Overlay</label>
    </settings>
    <formElements>
        <select>
            <settings>
                <options class="\Magento\Config\Model\Config\Source\Yesno"/>
            </settings>
        </select>
    </formElements>
</field>

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.