Search code examples
phpmagentobackendfield

Create Magento Backend Field ReadOnly


I would like to create a read-only field in the backend at the client's Magento. create fields to know (through a module) is as follows:

 $installer->addAttribute("customer", "attrcode",  array(
     "type"     => "varchar",
     "backend"  => "",
     "label"    => "label",
     "input"    => "text",
     "source"   => "",
     "visible"  => true,
     "required" => false,
     "default" => "",
     "frontend" => "",
     "unique"     => false,

    ));

this way it creates the field, but he's not just reading ...

Thank You


Solution

  • One possible solution is to use javascript to disable the button on page load

    Create a js file and upload it to your admin skin/js directory (disable_button.js)

    add

    document.observe('dom:loaded', function(){
         $("target_input_id").disabled=true;
    });
    

    Then add or update you local.xml to include the js files

    <?xml version="1.0"?>
    <layout version="0.1.0">
        <adminhtml_customer_edit>
            <reference name="head">
                <action method="addItem"><type>skin_js</type><script>js/disable_button.js</script></action>
            </reference>
        </adminhtml_customer_edit>
    </layout>