9

I want to add a category selector on a new tab in my admin form. Please help me to do the same or provide me a suitable tutorial. enter image description here

1 Answer 1

5

If you just want to add tree input renderer you can add this code in your ui component form 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>
7
  • Is it necessary to add admin form using ui component? Now I am not using ui component form ,that's why I asked.
    – E.B
    Commented Dec 9, 2016 at 5:04
  • Ok .Let me start creating form using ui component.
    – E.B
    Commented Dec 9, 2016 at 5:51
  • How can i save the selected categories to my db ?
    – E.B
    Commented Dec 12, 2016 at 7:14
  • 1
    when you post your form you will get values of selected categories in form of array. You can implode it and save it in form of comma separated values
    – Priyank
    Commented Dec 12, 2016 at 7:45
  • Does $data['parent'] in save.php contains that array?
    – E.B
    Commented Dec 12, 2016 at 8:37

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.