depend not working in system.xml
-
12-12-2019 - |
Question
I created system.xml
file like below and set all fields depend on active
field but some of them doesn't work and display even active
field is disabled
system.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>
....
in above file get_settings
doesn't work but title
work as well !
What is different between them?
and Settings.php in 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;
}
}
but didn't use $element
in codes!
Solution
Just tested your code and it seems to work fine on the title
config. It doesn't work on the get_settings
config because the Javascript that does the behind the scenes work requires that you have an input field with the correct ID.
So to get this to work, you would have to add a hidden input field, can be a dummy input field if you like, but the id must follow your config settings, so i would suggest you inspect element on one of the other input fields and follow suit
To do this just your Settings.php
with the following:
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;
}
Thats it. Remember, the depends tag only works when there is an input field available in the source with the correct id's.