There is a better way, but you need to override the core files
Override the method in the following file Application \ code \ core \ Mage \ Adminhtml \ Block \ Widget \ Form \ Element \ Dependence.php
public function addFieldDependence($fieldName, $fieldNameFrom, $refValues) { $this->_depends[$fieldName][$fieldNameFrom] = $refValues; return $this; }
In the application \ code \ core \ Mage \ Adminhtml \ Block \ System \ Config \ Form.php Change the initFields method
if ($e->depends) { foreach ($e->depends->children() as $dependent) { $dependentId = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $dependent->getName(); if ($dependent->count()) { $dependentValue = (array) $dependent; $dependentValue = array_values($dependentValue); } else { $dependentValue = (string) $dependent; } $this->_getDependence() ->addFieldMap($id, $id) ->addFieldMap($dependentId, $dependentId) ->addFieldDependence($id, $dependentId, $dependentValue); } }
Modify javascript js \ mage \ adminhtml \ form.js file
trackChange : function(e, idTo, valuesFrom) { // define whether the target should show up var shouldShowUp = true; for (var idFrom in valuesFrom) { if (valuesFrom.hasOwnProperty(idFrom)) { if (typeof(valuesFrom[idFrom])=="object") { shouldShowUp = false; for(var idVal in valuesFrom[idFrom]) { if (valuesFrom[idFrom].hasOwnProperty(idVal)) { if (typeof(idVal)!="undefined" && ($(idFrom).value == valuesFrom[idFrom][idVal])) { shouldShowUp = true; } } } } else if (typeof(valuesFrom[idFrom])=="string") { if ($(idFrom).value != valuesFrom[idFrom]) { shouldShowUp = false; } } } /* if ($(idFrom).value != valuesFrom[idFrom]) { shouldShowUp = false; } */ } // toggle target row if (shouldShowUp) { $(idTo).up(this._config.levels_up).select('input', 'select', 'td').each(function (item) { if (!item.type || item.type != 'hidden') { // don't touch hidden inputs, bc they may have custom logic item.disabled = false; } }); $(idTo).up(this._config.levels_up).show(); } else { $(idTo).up(this._config.levels_up).select('input', 'select', 'td').each(function (item){ if (!item.type || item.type != 'hidden') { // don't touch hidden inputs, bc they may have custom logic item.disabled = true; } }); $(idTo).up(this._config.levels_up).hide(); } }
Use the following syntax to depend on multiple values ββon your xml
<depends> <field1> <val1>text</val1> <val2>radio</val2> </field1> </depends>
Andrew Aculana
source share