Oh snap! You are using an old version of browser. Update your browser to get new awesome features. Click for more details.

Magento how to renderer admin form field

Hi Friend,

You can easily rendere you admin form.php file(Edit/Add New Action File).

First Method ::

Renderer file:

Date.php

class [NameSpace]_[ModuleName]_Block_Adminhtml_Edit_Renderer_Date extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{  
   public function render(Varien_Object $row)    {
        //Get render element value
        $_elementvalue = $row->getValue();

        //Your Code Here

        return $_elementvalue;
    }
}

in your form.php

$nextdate = $fieldset->addField('next_date', 'date',
array(
'name'      => 'next_date',
'label'     => 'Close Date',
'class'     => 'required-entry validate-date validate-date-range date-range-custom_theme-from',
'required'  => true,
'image'     => $this->getSkinUrl('images/grid-cal.gif'),
'format'    => 'YYYY-MM-dd',
//'value'   => $array['next_date']
));

//Set your renderer file path here
$renderer = new [NameSpace]_[ModuleName]_Block_Adminhtml_Edit_Renderer_Date();
$nextdate->setRenderer($renderer);


Second Method ::


Renderer file:

Date.php

class [NameSpace]_[ModuleName]_Block_Adminhtml_Edit_Renderer_Date extends Varien_Data_Form_Element_Abstract
{
protected $_element;

    public function getElementHtml(Varien_Object $row){
    //Get render element value
    $_elementvalue = $this->getValue();

        //Your Code Here

        return $_elementvalue;
    }
}

in your form.php

//Set your renderer file path here
$fieldset->addType('date', '[NameSpace]_[ModuleName]_Block_Adminhtml_Edit_Renderer_Date');

$fieldset->addField('next_date', 'date',
array(
'name'      => 'next_date',
'label'     => 'Close Date',
'class'     => 'required-entry validate-date validate-date-range date-range-custom_theme-from',
'required'  => true,
'image'     => $this->getSkinUrl('images/grid-cal.gif'),
'format'    => 'YYYY-MM-dd',
//'value'   => $array['next_date']
));

5 comments