Magento 2: Dependent Groups on System Configuration

adminsystem-configsystem.xml

I know that to create a dependency for fields it's possible to use the node

<depends />

That said, I've been trying several ways to create a group dependency but I can't seem to find a way to make Magento use it, on the actual Form.php code it mentions

$dependent->fieldset

So it might be there but I haven't been able to leverage it.

Edit: On further investigation it seems it only loops through fields to read dependencies since on Mage_Adminhtml_Block_System_Config_Form::initFields()

foreach ($group->fields as $elements) {

It would still be a good thing to know how to achieve this

Best Answer

You can put JavaScript in the comment area. It can be something like this:

<comment><![CDATA[
    <script type="text/javascript">
        document.observe("dom:loaded",function(){
            if($('sections_groups_value').value != some_value){
                 Element.up($('sections_groups')).hide();
            }
        });
        Event.observe('sections_groups_value', 'change', function(){
            if(this.value != some_value){
                Element.up($('sections_groups')).hide();
            }else if(this.value == some_value){
                Element.up($('sections_groups')).show();
            }
        })
    </script>]]>
</comment>

Replace "sections_groups_value", "some_value" and "sections_groups" accordingly.