So you can set in the system.xml file of a module a dependency between fields by adding a <depends> tag in one of the fields.
<field1>
 ....
</field1>
<field2>
 ....
 <depends>
 <field1>1</field1>
 </depends>
</field2>
The code above means that field2 will be shown when the value of field1 is 1. 
I want to know how/if can I tell Magento to show field2 if the value for field1 is 1 OR 2?
3 Answers 3
Try this:
<depends>
 <field separator="|">
 <value>1|2|3</value>
 </field>
</depends>
- 
 Do you know that this works, or are you just putting it out there?benmarks– benmarks2014年02月17日 00:04:13 +00:00Commented Feb 17, 2014 at 0:04
- 
 1Dude...I don't know how, but this actually works. Now I'm ashamed and sorry for all my bad words I said to the guys that implemented the config section. For some reason$dependent['separator']returns the value of the attributeseparator. To whom ever downvoted this, please upvote (twice if possible). Works perfectly. Thanks. cc @benmarksMarius– Marius2014年02月17日 07:16:48 +00:00Commented Feb 17, 2014 at 7:16
- 
 1This working != it being a good idea. I think there's no need to apologize for your words :-Dbenmarks– benmarks2014年02月17日 13:27:28 +00:00Commented Feb 17, 2014 at 13:27
- 
 verrrrrry cool! This appears to also be working in Magento 2.sdaugherty– sdaugherty2021年08月22日 03:50:30 +00:00Commented Aug 22, 2021 at 3:50
[EDIT]
I was wrong in my answer below. I will not delete it (yet) because I got 7 upvotes on this :). But I'm editing it so you all have the chance to retract your vote (even downvote it, because I deserve it).
Original Answer
Ha!..I found it.
Short answer: You cannot!
Long answer: You should be able to do it if someone would have known the difference between an array and an object.
In theory this should work
<field1>
 ....
</field1>
<field2>
 ....
 <depends>
 <field1>
 <value>1|2</value>
 <separator>|</separator>
 </field1>
 </depends>
</field2>
But in the code that handles the dependency, Mage_Adminhtml_Block_System_Config_Form::initFields around line 366 there is this code
if (isset($dependent['separator'])) {
 $dependentValue = explode((string)$dependent['separator'], $dependentValue);
}
$dependent is always an object so $dependent['separator'] is never set.
If I change the code above to 
if (isset($dependent->separator)) {
 $dependentValue = explode((string)$dependent->separator, $dependentValue);
}
everything works smoothly.
I guess I cannot change the core just for the sake of an extension so I have to create 2 fields instead of 1, one for each value from field1 or create a custom js that handles this and add it to the config page.
- 
 2Damn it. I know this kind of bugs :-) I hope you reported it? Great insight!Fabian Blechschmidt– Fabian Blechschmidt2013年10月24日 17:39:27 +00:00Commented Oct 24, 2013 at 17:39
- 
 1Oh man that is some great investigation are you sure you are not Sherlock? +1 for reporting it.David Manners– David Manners2013年10月24日 20:07:01 +00:00Commented Oct 24, 2013 at 20:07
- 
 2@DavidManners elementary my dear watsonMarius– Marius2013年10月24日 20:30:21 +00:00Commented Oct 24, 2013 at 20:30
I know this was asked under Magento 1 but since I landed here looking for an example for Magento 2 and the answers here pointed me in the right direction, here is a working example tested in Magento 2.4.4 in case it helps anyone else:
<field id="time" translate="label comment" type="time" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Start Time</label>
<depends>
 <field id="frequency" separator="|">D|W|M</field>
</depends>
There is also a negative parameter that can be used to tailor the condition even more.
enter image description here