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

15

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>
  • Genius! May I ask where you got this information from for future reference? – stewrat Oct 27 '16 at 5:44
  • You are at right place bro. Just keep searching :) – Priyank Oct 27 '16 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 – Vasilii Burlacu Nov 19 '16 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 Nov 20 '16 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. – Vasilii Burlacu Nov 22 '16 at 18:47

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.