依赖不工作的系统。xml
-
12-12-2019 - |
题
我创造了 system.xml
像下面这样的文件并设置所有字段取决于 active
场,但其中一些不工作,甚至显示 active
场是 残疾人士
系统。xml
<fields>
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<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>
</active>
<get_settings translate="label">
<label>Account Info</label>
<frontend_type>label</frontend_type>
<frontend_model>module/adminhtml_settings</frontend_model>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<depends><active>1</active></depends>
</get_settings>
<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<depends><active>1</active></depends>
</title>
....
在上述文件中 get_settings
不起作用,但 title
也工作吧!他们之间有什么不同?
和设置。php在 module/adminhtml_settings
class Name_Module_Block_Adminhtml_Settings extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
....
....
return $html;
}
}
但没有使用 $element
密码里!
解决方案
刚刚测试了你的代码,它似乎在 title
配置。这对......不起作用。 get_settings
配置,因为做幕后工作的Javascript需要您有一个具有正确ID的输入字段。
所以要做到这一点,你必须添加一个隐藏的输入字段,如果你愿意,可以是一个虚拟的输入字段,但id必须遵循你的配置设置,所以我建议你检查其他输入
要做到这一点只是你的 Settings.php
与以下:
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$html = $element->getElementHtml();
$html .= '<input id="name_module_get_settings" name="groups[module_name][fields][titles][value]" value="" class=" input-text" type="hidden">';
/** do what ever you want here **/
return $html;
}
就这样。请记住,depends标记仅在源中有一个具有正确id的输入字段时才起作用。