Menu Close
    Hire Us Request Quote Reading List Switch to Dark Mode

    Add fields in admin Category Form magento2

    Today we are discussing how to add custom attributes/fields in category add/edit page in admin panel in  magento2.

    Firstly you have to create attribute for category.

    For example: you have created an attribute with attribute_code: “category_test_field”.

    Now, in magento 2.1.0 it does not displays the attributes by default in the form, to display attribute in category form you have to define it in ui_component.

    Now, create a file under app/code/Webkul/Test/view/adminhtml/ui_component/category_form.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <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="category_test_field">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="sortOrder" xsi:type="number">50</item>
                        <item name="dataType" xsi:type="string">varchar</item>
                        <item name="formElement" xsi:type="string">input</item>
                        <item name="label" xsi:type="string" translate="true">Commission Test Field</item>
                        <item name="default" xsi:type="number">0</item>
                    </item>
                </argument>
            </field>
        </fieldset>
    </form>
    

    Here,

    category_from.xml : file name should be same, because we add a field in existing form. category_form is already defined in magento/catalog to display form.

    <fieldset name=’general’> : is the name of group in which you want to display your field.

    <field name=’category_test_field’> : is the attribute code to set/get the values of attribute.

    sortorder : is the number in which position you want your field in the form.

    datatype : is the type of data in which it stores the data.

    formelement : which type of form element you want to display for your attribute. for example: input, select, checkbox, etc.

    label : label of the attribute.

    default : default value to display.

    After this your field is displayed on the category form.

    Thank you.

    . . .

    Comment (1)

    Add Your Comment

  • Ragubathi U
    Thanks for the post.I have problem with saving the custom field added by above code.Do I wanna create attribute in Stores->Product Attributes?
  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close