Skip to main content
1 of 4
jmk
  • 771
  • 1
  • 6
  • 12

system.xml dependencies across groups

The system.xml allows us to make individual fields dependent upon values from other fields. The goto article is of course from Alan Storm: In Depth Magento System Configuration

It looks something like this (I am borrowing his example code here):

Location: app/code/local/Alanstormdotcom/Helloworld/etc/system.xml

<config>
<tabs>
    <helloconfig translate="label" module="helloworld">
        <label>Hello Config</label>
        <sort_order>99999</sort_order>
    </helloconfig>
</tabs>
<sections>
    <helloworld_options translate="label" module="helloworld">
        <label>Hello World Config Options</label>
        <tab>helloconfig</tab>
        <frontend_type>text</frontend_type>
        <sort_order>1000</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
        <groups>
            <notes translate="label">
                <label>Demo Of Config Fields NOTES</label>
                <frontend_type>text</frontend_type>
                <sort_order>1</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <fields>
                    <enabled translate="label">
                        <label>Enabled</label>
                        <frontend_type>select</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </enabled>
                    <hello_note>
                        <label>Message</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>2</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                        <depends>
                            <enabled>1</enabled>
                        </depends>
                    </hello_note>
                </fields>
            </notes>
            <messages translate="label">
                <label>Demo Of Config Fields MESSAGES</label>
                <frontend_type>text</frontend_type>
                <sort_order>1</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <fields>
                    <hello_message>
                        <label>Message</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </hello_message>
                    <hello_time>
                        <label>Time to Say Hello</label>
                        <frontend_type>time</frontend_type>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </hello_time>
                </fields>
            </messages>
        </groups>
    </helloworld_options>
</sections>

But how do I make the <hello_message> dependent on <enabled> field?

jmk
  • 771
  • 1
  • 6
  • 12