0

I am trying to display time chooser in magento date picker but it didn't how up.

can anyone please guide on this how to set timer in magento system confif.

I have followed This Link but it show only date picker.

1

You need to make changes in the _getElementHtml() function.

Please replace the _getElementHtml() function with below code:

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

    $data = array(
        'name'      => $element->getName(),
        'html_id'   => $element->getId(),
        'image'     => $this->getSkinUrl('images/grid-cal.gif'),
    );
    $date->setTime(true); // added this new line of code
    $date->setData($data);
    $date->setValue($element->getValue(), $format);
    $date->setFormat(Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
    $date->setClass($element->getFieldConfig()->validate->asArray());
    $date->setForm($element->getForm());

    return $date->getElementHtml();
}

I have made changes in 3 places:

Step 1:

$date = new Varien_Data_Form_Element_Date;

to

$date = new Varien_Data_Form_Element_Datetime;

Step 2:

$format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);

to

$format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);

Step 3:

$date->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));

to

$date->setFormat(Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));

and

Step 4:

$date->setTime(true); // added this new line of code

| improve this answer | |
  • I think this should be $date = new Varien_Data_Form_Element_Date; when i use $date = new Varien_Data_Form_Element_Datetime; it gives error like Fatal error: Class 'Varien_Data_Form_Element_Datetime' not found because there is no file like Datetime in Element folder. – Pradip Garchar Nov 22 '17 at 8:06
  • I have checked my code in Magento 1.9. It may be possible that the class does not exist in Magento 1.8 – Mohit Kumar Arora Nov 22 '17 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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