2

In the custom edit form, I want to add a custom tab in admin form.

enter image description here

Someone plz help me to solve this

2 Answers 2

1

Try below way.

Follow Create UI form link to create simple form without tab structure.

Now replace below code in a given below form.

Namespace/ModuleName/view/adminhtml/ui_component/employee_form.xml

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
    <item name="js_config" xsi:type="array">
        <item name="provider" xsi:type="string">employee_form_form.employee_form_form_data_source</item>
        <!--            <item name="deps" xsi:type="string">employee_form_form.employee_form_form_data_source</item>-->
    </item>
    <item name="label" translate="true" xsi:type="string">Label Options</item>
    <item name="config" xsi:type="array">
        <item name="dataScope" xsi:type="string">data</item>
        <item name="namespace" xsi:type="string">employee_form_form</item>
    </item>
    <item name="reverseMetadataMerge" xsi:type="boolean">true</item>        
</argument>
<settings>
    <buttons>
        <button class="Namespace\Modulename\Block\Adminhtml\Productlabel\Edit\BackButton" name="back"/>
        <button class="Namespace\Modulename\Block\Adminhtml\Productlabel\Edit\DeleteButton" name="delete"/>
        <button class="Namespace\Modulename\Block\Adminhtml\Productlabel\Edit\SaveButton" name="save"/>
        <button class="Namespace\Modulename\Block\Adminhtml\Productlabel\Edit\SaveAndContinueButton" name="save_and_continue"/>
        <button class="Namespace\Modulename\Block\Adminhtml\Productlabel\Edit\Duplicate" name="duplicate"/>
    </buttons>        
    <layout>
        <navContainerName>left</navContainerName>
        <type>tabs</type>
    </layout>
    <dataScope>data</dataScope>
    <deps>
        <dep>employee_form_form.employee_form_form_data_source</dep>
    </deps>
</settings>
<dataSource name="employee_form_form_data_source">
    <argument name="dataProvider" xsi:type="configurableObject">
        <argument name="class" xsi:type="string">Namespace\Modulename\Model\Productlabel\DataProvider</argument>
        <argument name="name" xsi:type="string">employee_form_form_data_source</argument>
        <argument name="primaryFieldName" xsi:type="string">productlabel_id</argument>
        <argument name="requestFieldName" xsi:type="string">productlabel_id</argument>
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="submit_url" xsi:type="url" path="managelabels/productlabel/save"/>
            </item>
        </argument>
    </argument>
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
        </item>
    </argument>
</dataSource>
<fieldset name="general">
    <settings>
        <label translate="true">General Info</label>
    </settings>
    <field name="productlabel_id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="visible" xsi:type="boolean">false</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Productlabel ID</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="source" xsi:type="string">data</item>
                <item name="dataScope" xsi:type="string">productlabel_id</item>
            </item>
        </argument>
    </field>
    <field name="labelname" formElement="input">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Label Name</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="source" xsi:type="string">data</item>
                <item name="dataScope" xsi:type="string">labelname</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                </item>
            </item>
        </argument>
    </field>        
</fieldset>

Let me know if you have any query/concern.

I hope it helps!

Note: Make sure you have created a route, controller, model & resource model and blok file. I have share only code to how to add Tab in form.

2
  • Thank you for the answer I have done it already by using this blog @Chirag Patel Commented Mar 30, 2019 at 11:41
  • OK, nop! You can also post your answer here :) Commented Mar 30, 2019 at 11:44
1

Add custom tab in the custom form in admin by following the below mentioned link:

https://www.mage-world.com/blog/grid-and-form-in-magento-2-admin-panel-part-2.html

1
  • This is old way of doing things
    – Avesh Naik
    Commented Apr 1, 2022 at 5:18

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.