12

The system.xml allows us to make the visibility of individual fields dependent on 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>

Since this seems to only work with fields inside the same group/fieldset (<notes> in this example), I want to know: is there a way to make <hello_message> from the <messages> group dependent on <enabled> from the <notes> group?

1 Answer 1

11

After consulting the appropriate core file a cross group/fieldset <depends> looks like this:

<!-- … -->
<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>
    <depends>
        <enabled>
            <fieldset>notes</fieldset>
            <value>1</value>
        </enabled>
    </depends>
</hello_message>
<!-- … -->

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.