1

I follower this tutorial. You can add easily fields as input text or dropdown, but in my case I want to add the magento datepicker.

I have this function :

public function _prepareToRender()
{
        $this->addColumn('holiday_name', array(
            'label' => Mage::helper('mynamespace_mymodule')->__('Name'),
            'style' => 'width:100px',
            'renderer' => $this->_getRendererDate(),
        ));
}
protected function  _getRendererDate()
{
        if (!$this->_itemRenderer) {
            $this->_itemRenderer = $this->getLayout()->createBlock(
                'mynamespace_mymodule/config_adminhtml_form_field_holidaydate', '',
                array('is_render_to_js_template' => true)
            );
        }
        return $this->_itemRenderer;
}

and this is my block, which extends this class: Mage_Adminhtml_Block_System_Config_Form_Field

protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $date = new Varien_Data_Form_Element_Date;
        $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);

        $data = array(
            'name'      => $element->getName(),
            'html_id'   => $element->getId(),
            'image'     => $this->getSkinUrl('images/grid-cal.gif'),
        );
        $date->setData($data);
        $date->setValue($element->getValue(), $format);
        $date->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
        $date->setForm($element->getForm());

        return $date->getElementHtml();
    }

This is not working, any ideas how can make this work ? thx

1 Answer 1

0
$fieldset->addField('purchase_date', 'date', array(
                'name'               => 'date',
                'label'              => Mage::helper('usercontact')->__('Purchase Date'),
                'tabindex'           => 1,
                'image'              => $this->getSkinUrl('images/grid-cal.gif'),
                'format'             => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT) ,
                'value'              => date( Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
                                              strtotime('next weekday') )
            ));

you use this code to add datepicker field in your form

2
  • ok, where should I add this ? Did you check the article ? Sep 22, 2016 at 12:26
  • when you create form in admin that time this code is used. Sep 22, 2016 at 12:38

Your Answer

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

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