在 alanstorm/magento_system_configuration_in_depth_tutorial @AlanStorm给出了一个很好的教程的系统配置.
In alanstorm/magento_system_configuration_in_depth_tutorial @AlanStorm gives a very good tutorial for system configuration.
他还解释了如何使用< depends>标记仅在另一个字段中设置了特定值时才显示该字段.
He also explains how to use a <depends> tag to make a field show only when a specific value is set in another field.
我的Q是我怎样才能使如果字段A有任一值V1或V2 fieldB可见. 以及是否有与在<任何其他选项;取决于>
My Q is how can I make fieldB visible if field A has either value V1 or V2. and are there any other options with the <depends> ?
此外,如果有人知道在Magento的代码,这是实现我也想看看在自己的代码
Also If someone knows where in magento's code this is implemented I would also like to have a look at the code myself.
谢谢
推荐答案有一个更好的办法,但你需要重写核心文件
There is a better way, but you will need to override the core files
覆盖以下文件下的方法 应用\代码\核心\法师\ Adminhtml \块\的widget \表格\元素\ Dependence.php
Override the method under the following file app\code\core\Mage\Adminhtml\Block\Widget\Form\Element\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; }在该应用\代码\核心\法师\ Adminhtml \块\ SYSTEM \配置\ form.php的 修改方法initFields
On the app\code\core\Mage\Adminhtml\Block\System\Config\Form.php Modify the method initFields
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); } }
修改JavaScript文件的js \法师\ adminhtml \ form.js
Modify the javascript file js\mage\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(); } }使用以下语法多个值依赖于你的XML
Use the following syntax for multiple values dependency on your xml
<depends> <field1> <val1>text</val1> <val2>radio</val2> </field1> </depends>更多推荐
一个magento adminhtml字段可以取决于一个以上的字段或值吗?
发布评论