Skip to content

How to depend a field to a field having type=”checkbox” in system.xml?

i am new to magento..i am facing issue while learning configuration of system.xml..i want to depend a field of type=”dropdown” to field of type=”checkbox”..any help would be appreciated..here is my system.xml file..thanks in advance..

System.xml

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="ktplmodule" translate="label" sortOrder="50">
            <label>KTPL</label>
        </tab>
        <section id="section_extension" showInDefault="1">
            <tab>ktplmodule</tab>
            <label>DynamicRow</label>
            <resource>Ktpl_DynamicRow::config_extension</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Configuration</label>
                <field id="dynamic_field" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Dynamic Field</label>
                    <backend_model>KtplDynamicRowBlockAdminhtmlConfigBackendArraySerialized</backend_model>
                    <frontend_model>KtplDynmicRowBlockAdminhtmlDynamicFieldData</frontend_model>
                </field>

                <field id="dynamic_field1" type="textarea" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Demo</label>
                    <!-- <backend_model>KtplDynamicRowBlockAdminhtmlConfigBackendArraySerialized</backend_model>
                    <frontend_model>KtplDynamicRowBlockAdminhtmlDynamicFieldData</frontend_model> -->
                </field>

                <field id="checkbox" type="checkbox" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Checkbox</label>
                    <comment>Select this for below dropdown</comment>

                </field>

                <field id="dropdown_example" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                     <label>Dropdown with custom source model example</label>

                <source_
model>KtplDynamicRowModelConfigSourceCustom</source_model>

                <depends>
                     <field id="checkbox">checked</field>
                    </depends> //want to make this field dependent on above one..

                </field>
            </group>
        </section>
    </system>

</config>