Question

Can anyone tell my how I can show a select box field in the system configuration as disabled?

I want to have a status field that shows the status of a job (running/not running). When the value is "running" I want to show a button that can stop the job.

My current approach is to have a <frontend_type>select</frontend_type> for the status and the button uses <depends> in order to decide if it is shown or not. So far this works as expected. But I don't want the select to be editable. Varien_Data_Form_Element_Select checks for attributes like readonly and disabled but how can I activate them? Is there a simple solution besides writing a custom frontend_model?

As a sidenote: I would not need a select box to do this. A label would be more than enough. Unfortunately the Magento's form.js seems to stick to input or select when checking depends

Thanks in advance! :-)

Was it helpful?

Solution

You can specify a frontend model to your field like this:

<field_name translate="label">
    <label>Field name</label>
    <frontend_type>select</frontend_type>
    <frontend_model>module/field_name_renderer</frontend_model><!-- this is it -->
    <source_model>adminhtml/system_config_source_yesno</source_model>
    <sort_order>10</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</field_name>

Now you have to create the class for that frontend model. This is not actually a model it's a block.

<?php 
class Namespace_Module_Block_Field_Name_Renderer extends Mage_Adminhtml_Block_System_Config_Form_Field{
    protected function _getElementHtml($element) {
        if (YOUR CONDITION HERE) {
            $element->setDisabled('disabled');
        }
        return parent::_getElementHtml($element);
    }
}

As for side note...I have no idea...yet.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top