Reading list Switch to dark mode

    Create a dependant field in admin configuration in magento 2

    Let’s create a dependant field in admin configuration in magento 2.

    In this article we will learn how to create a dependant field in admin configuration in magento 2.

    So, the file which is used to define configurations in admin is system.xml. I  suppose that you know where this file is located in a custom module.

    So, here is the code in which, on select a option with value “1” from a drop-down list a text field (dependson) will appear :

    <!-- this is a drop-down field which contains options -->
    <field id="custom" translate="label comment" sortOrder="1" type="select" showInDefault="1" showInWebsite="1" showInStore="1">
        <label>Please Select a Value : </label>
        <!-- source file contains the array of options of drop-down list -->
    <!-- this is a text field which depends on the option value -->
    <field id="dependson" translate="label comment" sortOrder="2" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
        <label>Enter the Name : </label>
            <field id="custom">1</field>

    And if you want to create a field dependant on two or more values, use the below code :

    Searching for an experienced
    Magento 2 Company ?
    Read More
        <field id="custom" separator=",">0,1</field>

    In above code if you select options with values “0” or “1” from drop-down list then the text- field will be appeared in the admin configuration.

    That’s all in this article, hope it will help you to add a dependant field in admin configuration. Try the above code and if you have any issue just comment below. 🙂

    . . .
    Add a comment

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top
    We endeavoured to re-platform our existing site and Webkul has been playing an integral part as far as transforming our basic Magneto instance into an online marketplace.
    Alex Maranduik
    Director, Marketing
    Talk to Sales


    Live Chat

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home