2

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!

2
  • How does the frontend model class for get_settings looks like? I mean module/adminhtml_settings. I bet that has something to do with your issue.
    – Marius
    Commented Apr 29, 2015 at 21:28
  • @Marius: I updated code in first code, I test it with "Alan Storm" alanstorm.com/magento_system_configuration_in_depth_tutorial for frontend_model like "Last Update" , it do not work too!
    – sIiiS
    Commented Apr 29, 2015 at 21:36

1 Answer 1

3

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.

1
  • Great job, your answer is true!
    – sIiiS
    Commented Apr 29, 2015 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.