0

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>Ktpl\DynamicRow\Block\Adminhtml\Config\Backend\ArraySerialized</backend_model>
                    <frontend_model>Ktpl\DynmicRow\Block\Adminhtml\DynamicFieldData</frontend_model>
                </field>

                <field id="dynamic_field1" type="textarea" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Demo</label>
                    <!-- <backend_model>Ktpl\DynamicRow\Block\Adminhtml\Config\Backend\ArraySerialized</backend_model>
                    <frontend_model>Ktpl\DynamicRow\Block\Adminhtml\DynamicFieldData</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>Ktpl\DynamicRow\Model\Config\Source\Custom</source_model>

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

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

</config>

1 Answer 1

2

Please try with the below code.

<?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>Ktpl\DynamicRow\Block\Adminhtml\Config\Backend\ArraySerialized</backend_model>
                <frontend_model>Ktpl\DynmicRow\Block\Adminhtml\DynamicFieldData></frontend_model>
            </field>
            <field id="dynamic_field1" type="textarea" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Demo</label>
                <!-- <backend_model>Ktpl\DynamicRow\Block\Adminhtml\Config\Backend\ArraySerialized</backend_model>
                <frontend_model>Ktpl\DynamicRow\Block\Adminhtml\DynamicFieldData</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>Ktpl\DynamicRow\Model\Config\Source\Custom</source_model>
            <depends>
                <field id="checkbox">checked</field>
                <depends>
                    <field id="dynamic_field1">1</field>
                </depends>
            </field>
        </group>
    </section>
</system>
2
  • This is not working..and i want that field to be dependent on checkbox and not dynamic field Jun 26, 2023 at 11:24
  • Replace the value dynamic_field1 with the name of the field you want to depend on. So here you should use checkbox. Note : This code can't work as is, this is a copy of the code you added in your question, which contains XML errors (probably copy/paste errors). More specificaly, take a look at the "frontend_model" value of the dynamic_field1 node : there is a wrong value there
    – Cladiuss
    Jun 26, 2023 at 12:02

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.