如何在自定义表单中使用Magento 2产品添加/编辑表单类别树结构?


10

我正在尝试在自定义表单中使用Magento 2产品添加/编辑表单类别树结构

我得到些溶胶。从StackOverflow和其他一些网站

但它不能正常工作

我努力了 :

    $fieldset->addField(
        'category_ids',
        'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Category',
        [
            'name' => 'category_ids',
            'title' => 'Category',
            'label' => 'Category'
        ]
    );

<head>
    <css src="Magento_Catalog::catalog/category-selector.css"/>
</head>

这段代码,并以我的自定义形式添加了此CSS

但它显示像这样

在此处输入图片说明

但我需要与产品添加/编辑表单相同

在此处输入图片说明

我怎样才能做到这一点

请分享一些建议.....


1
您好@Yagendra,您找到任何解决方案了吗?
Vinaya Maheshwari'17年

Answers:


2

如果使用ui组件创建表单,则可以从以下xml获取类别输入

<field name="parent">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Magento\Catalog\Ui\Component\Product\Form\Categories\Options</item>
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string" translate="true">Parent Category</item>
                    <item name="componentType" xsi:type="string">field</item>
                    <item name="formElement" xsi:type="string">select</item>
                    <item name="component" xsi:type="string">Magento_Catalog/js/components/new-category</item>
                    <item name="elementTmpl" xsi:type="string">ui/grid/filters/elements/ui-select</item>
                    <item name="dataScope" xsi:type="string">data.parent</item>
                    <item name="filterOptions" xsi:type="boolean">true</item>
                    <item name="showCheckbox" xsi:type="boolean">false</item>
                    <item name="disableLabel" xsi:type="boolean">true</item>
                    <item name="multiple" xsi:type="boolean">false</item>
                    <item name="levelsVisibility" xsi:type="number">1</item>
                    <item name="sortOrder" xsi:type="number">20</item>
                    <item name="required" xsi:type="boolean">true</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                    <item name="listens" xsi:type="array">
                        <item name="${ $.namespace }.${ $.namespace }:responseData" xsi:type="string">setParsed</item>
                    </item>
                </item>
            </argument>
        </field>

我试图弄清楚如何创建按钮和模式。


0

下面有一个多选解决方案:

<field name="category_ids" component="Magento_Catalog/js/components/new-category" sortOrder="20" formElement="select">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="filterOptions" xsi:type="boolean">true</item>
            <item name="multiple" xsi:type="boolean">true</item>
            <item name="showCheckbox" xsi:type="boolean">true</item>
            <item name="disableLabel" xsi:type="boolean">true</item>
            <item name="levelsVisibility" xsi:type="number">1</item>
        </item>
    </argument>
    <settings>
        <required>true</required>
        <validation>
            <rule name="required-entry" xsi:type="boolean">true</rule>
        </validation>
        <elementTmpl>ui/grid/filters/elements/ui-select</elementTmpl>
        <label translate="true">Categories</label>
        <dataScope>data.parent</dataScope>
        <componentType>field</componentType>
        <listens>
            <link name="${ $.namespace }.${ $.namespace }:responseData">setParsed</link>
        </listens>
    </settings>
    <formElements>
        <select>
            <settings>
                <options class="Magento\Catalog\Ui\Component\Product\Form\Categories\Options"/>
            </settings>
        </select>
    </formElements>
</field>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.