0

I have a category with subcategories, and I want to have the subcategory visible from the beginning, when the user opens the category selector.

Currently, the user has to click the arrow next to the parent category to expand it and have access to the subcategory when choosing categories. This needs to be auto-expanded, as soon as the user opens the category selection when creating a new product.

enter image description here

1

You can use this tag in config if you are creating it in ui-component.

<item name="levelsVisibility" xsi:type="number">3</item>

change the number according to your required levels.

        <field name="category_id">
        <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">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">category_id</item>
                <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="sortOrder" xsi:type="number">30</item>
                <item name="required" xsi:type="boolean">true</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">false</item>
                </item>
                <item name="listens" xsi:type="array">
                    <item name="${ $.namespace }.${ $.namespace }:responseData" xsi:type="string">setParsed</item>
                </item>
            </item>
        </argument>
    </field>
  • 1
    This attempt works. But in order to replace the old category selector, you have to add <field name="category_ids"> <argument name="data" xsi:type="array"> <item name="disabled" xsi:type="boolean">true</item> </argument> </field> and you have to change the value of dataScope from category_id to category_ids, else the values won't be saved. – Dorni Apr 24 at 5:28

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.