1

How can I create my custom category dropdown in admin side(Create category page) like an image

enter image description here

1 Answer 1

-1

If you want to add the Categories dropdown to the Category Edit pages in admin area, you should create file app/code/Vendor/Module/view/adminhtml/ui_component/category_form.xml in your custom module with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="general">
        <field name="featured_category_ids" sortOrder="100" formElement="select" component="Magento_Ui/js/form/element/ui-select">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filterOptions" xsi:type="boolean">true</item>
                    <item name="showCheckbox" xsi:type="boolean">true</item>
                    <item name="disableLabel" xsi:type="boolean">true</item>
                    <item name="multiple" xsi:type="boolean">true</item>
                    <item name="levelsVisibility" xsi:type="number">1</item>
                    <item name="listens" xsi:type="array">
                        <item name="${ $.namespace }.${ $.namespace }:responseData" xsi:type="string">setParsed</item>
                    </item>
                </item>
            </argument>
            <settings>
                <label translate="true">Featured Categories</label>
                <dataType>text</dataType>
                <elementTmpl>ui/grid/filters/elements/ui-select</elementTmpl>
            </settings>
            <formElements>
                <select>
                    <settings>
                        <options class="Magento\Catalog\Ui\Component\Product\Form\Categories\Options"/>
                    </settings>
                </select>
            </formElements>
        </field>
    </fieldset>
</form>

This will add a dropdown to the 'General' section of the form:

enter image description here

You can find more info about the UI-select component in Magento DevDocs

5
  • thanks for answwer, can you add this for product create page? and how?
    – NoOn
    Nov 17, 2021 at 10:03
  • For product create page - all the same. Only use 'product_form.xml' file name instead of 'category_form.xml'. And also change the fieldset name from "general" to "product-details". Nov 17, 2021 at 10:39
  • I need some installData file or note?
    – NoOn
    Nov 17, 2021 at 10:43
  • I have empty module
    – NoOn
    Nov 17, 2021 at 10:43
  • Do you know how to save value of multiselect?. After click on save button it doesnt save.
    – NoOn
    Nov 17, 2021 at 11:11

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.