0

I am trying at custom attribute to category edit form in Magento 2.2.3 admin.

I have created category_form.xml at below path.

Vendor/Module/view/adminhtml/ui_component/catgory_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="is_master_category">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="sortOrder" xsi:type="number">110</item>
                <item name="dataType" xsi:type="string">boolean</item>
                <item name="formElement" xsi:type="string">checkbox</item>
                <item name="source" xsi:type="string">category</item>
                <item name="prefer" xsi:type="string">toggle</item>
                <item name="valueMap" xsi:type="array">
                    <item name="true" xsi:type="string">1</item>
                    <item name="false" xsi:type="string">0</item>
                </item>
                <item name="default" xsi:type="string">1</item>
                <item name="label" xsi:type="string" translate="true">Is Master Category</item>
                <item name="notice" xsi:type="string" translate="true"></item>
                <item name="additionalClasses" xsi:type="string"></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>
        </argument>
    </field>

</fieldset>

Above code is working fine, Attribute is there but now i think it looks different, So i decided to create new fieldset and than want to add this attribute into it.

I tried below code but its not working.

<fieldset name="custom_fieldset" sortOrder="999">
    <settings>
        <collapsible>true</collapsible>
        <label translate="true">Custom Configurations</label>
    </settings>
    <field name="is_master_category">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="sortOrder" xsi:type="number">110</item>
                <item name="dataType" xsi:type="string">boolean</item>
                <item name="formElement" xsi:type="string">checkbox</item>
                <item name="source" xsi:type="string">category</item>
                <item name="prefer" xsi:type="string">toggle</item>
                <item name="valueMap" xsi:type="array">
                    <item name="true" xsi:type="string">1</item>
                    <item name="false" xsi:type="string">0</item>
                </item>
                <item name="default" xsi:type="string">1</item>
                <item name="label" xsi:type="string" translate="true">Is Master Category</item>
                <item name="notice" xsi:type="string" translate="true"></item>
                <item name="additionalClasses" xsi:type="string"></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>
        </argument>
    </field>

</fieldset>

Note: After dot i have add same code as above but its not working.

i cheked vendor file i think i've done same as them, but i think there is something is missing.

Please guide me, THanks in Advance

2
  • Can you add complete code ? Commented Mar 26, 2018 at 5:48
  • @zedBlackbeard, I've updated code.
    – anonymous
    Commented Mar 26, 2018 at 5:52

1 Answer 1

4

I think, this will help you.

<?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="custom_fieldset">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true">Custom Fieldset</item>
            <item name="collapsible" xsi:type="boolean">true</item>
            <item name="sortOrder" xsi:type="number">31</item>
        </item>
    </argument>
    <field name="is_master_category">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="sortOrder" xsi:type="number">10</item>
                <item name="dataType" xsi:type="string">boolean</item>
                <item name="formElement" xsi:type="string">checkbox</item>
                <item name="label" xsi:type="string" translate="true">Is Master Category</item>
                <item name="prefer" xsi:type="string">toggle</item>
                <item name="valueMap" xsi:type="array">
                    <item name="true" xsi:type="string">1</item>
                    <item name="false" xsi:type="string">0</item>
                </item>
                <item name="default" xsi:type="number">0</item>
            </item>
        </argument>
    </field>
  </fieldset>
</form>

And add Magento_Catalog sequence into module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Custom_Field" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Catalog"/>
        </sequence>
      </module>
</config>

Cheers !!

Updated.

7
  • It worked but just little bit issue if you can help, Fieldset added but, Default field like, Enable/Disable, Category name etc. also moved to bottom. Any Solution for that i need to keep all those at top. Same as before. prnt.sc/iwe46n
    – anonymous
    Commented Mar 26, 2018 at 6:23
  • Are you talking about sortOrder ? Commented Mar 26, 2018 at 6:26
  • Yes, I modified it but seems not working.
    – anonymous
    Commented Mar 26, 2018 at 6:27
  • So, Where you want to place ? bottom ? Commented Mar 26, 2018 at 6:34
  • below search engine optimization fieldset but, Default options like Enable/Disable, Cat name should be go up. As Default.
    – anonymous
    Commented Mar 26, 2018 at 6:35

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.