Editable List Item Field Using System Xml


Add field in your system xml file like below

<fields>
<product_additem translate="label">
                            <label>Media Source</label>
                            <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
							<frontend_model>synchronise/adminhtml_system_config_form_field_additem</frontend_model>	
                            <sort_order>31</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Add Item</comment>
                        </product_additem>	
										</fields>

Now you need to create a file to render html that is frontend_model.create file with Additem.php in your module adminhtml folder path.and write below code in it.

<?php
class <Namespace>_<Module>_Block_Adminhtml_System_Config_Form_Field_Additem extends Mage_Adminhtml_Block_System_Config_Form_Field_Regexceptions
{
    public function __construct()
    {
        $this->addColumn('title', array(
            'label' => Mage::helper('adminhtml')->__('Title '),
            'style' => 'width:120px',
        ));
        $this->addColumn('link', array(
            'label' => Mage::helper('adminhtml')->__('Link'),
            'style' => 'width:120px',
        ));
        $this->addColumn('image', array(
            'label' => Mage::helper('adminhtml')->__('Media'),
            'style' => 'width:120px',
        ));	
        $this->addColumn('content', array(
            'label' => Mage::helper('adminhtml')->__('Content'),
            'style' => 'width:220px',
        ));			
        $this->_addAfter = false;
        $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add Item');
        Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract::__construct();
    }
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $this->setElement($element);
        $html = $this->_toHtml();
        $this->_arrayRowsCache = null; // doh, the object is used as singleton!
        $html ='<div id="myeditableitem">'.$html.'</div>';
	return $html;
    }	
}

Now you have a editable field for your configuration setting like below images.
additem1

additem2

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s