Hay una forma mejor, pero tendrá que reemplazar los archivos del núcleo
reemplazar el método bajo el siguiente archivo aplicación \ code \ core \ Mago \ Adminhtml \ Bloquear \ Widget \ forma \ Elemento \ Dependence.php
public function addFieldDependence($fieldName, $fieldNameFrom, $refValues)
{
/*
if (is_array($refValues)) {
Mage::throwException('Dependency from multiple values is not implemented yet. Please fix to your widget.xml');
}
*/
$this->_depends[$fieldName][$fieldNameFrom] = $refValues;
return $this;
}
En la aplicación \ code \ core \ Mago \ Adminhtml \ Bloquear \ System \ Config \ form.php Modificar los initFields método
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);
}
}
modificar el archivo JavaScript JS \ mago \ \ adminhtml form.js
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();
}
}
Utilice la siguiente sintaxis para varios valores de la dependencia en su xml
<depends>
<field1>
<val1>text</val1>
<val2>radio</val2>
</field1>
</depends>
Gracias andrew. No he verificado esta solución pero parece sólida. Si alguien realmente intenta esto, publique un comentario. – epeleg
Lo probé, y CASI funcionó. Probablemente sea porque estoy en 1.6.2.0 y esta solución fue pensada para una versión anterior de Magento. De todos modos, revisa mi respuesta a continuación, si estás interesado. Ahora funciona para mí Gracias, Andrew! – pancake