Magento 2 system.xml Field Dependency on Multiple Values

When creating a system configuration field and that fields depend on one another, you have to add the dependency to the field of system.com. Magento provides a way to add dependency using the <depends> tag.

Sometimes that dependency is on more than one value. Like you want to display a specific field only when some specific values are selected for any field.

Below is how to create multiple values dependency in Magento 2

<field id="test_vish" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Test Field</label>
    <depends>
        <field id="any_attribute_id" separator="|">1|2|3</field>
    </depends>
</field>

We use a separator to assign dependency on multiple values. As per the above example, the “text_vish” filed will be visible when either 1 or 2 or 3 is selected for “any_attribute_id” field.

The separator is useful to assign dependency for multiple values of any same field. If you want to give dependency on multiple values of a different field of the system.xml file in Magento 2 then you can try below.

<field id="test_vish" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Test Field</label>
    <depends>
        <field id="first_attribute_id">1</field>
        <field id="second_attribute_id">1</field>
    </depends>
</field>