Magento Date Picker – Frontend and Admin:
Some times we have to implement datepicket for our customer module in magento frontend and admin section. For that we have to use like below way.
Frontend:
Call datepicker which one you want. You can use some Jquery Datepicker plugin. And call like below way
<li>
<label for=”dob” class=”required”><em>*</em><?php echo Mage::helper(‘mymodule’)->__(‘Date of Birth’) ?></label>
<div class=”input-box”>
<input type=”text” id=”dob” name=”dob” class=”input-text dob required-entry” readonly=”true”>
</div>
</li>
<script>
jQuery(“#dob”).datepicker({
dateFormat : “dd-mm-yy”,
changeMonth: true,
changeYear :true,
numberOfMonths: 1,
});
</script>
Admin:
Admin, also we can show date picker as like below
root\app\code\local\Jute\Mymodule\Block\Adminhtml\Mycustomer\Edit\Tab\Form.php
class Jute_Mymodule_Block_Adminhtml_Mycustomer_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$fieldset->addField(‘dob’, ‘date’, array(
‘name’ => ‘dob’,
‘label’ => Mage::helper(‘mymodule’)->__(‘Date of Birth’),
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘format’ => $dateFormatIso,
‘class’ => ‘validate-date validate-date-range date-range-date-from’
));
}
}
Once above code has been added, you will get following Error message, “Fatal error: Class ‘Mage_Events_Helper_Data’ not found magento”.
In this time, first we have to create one column in our MySql Table with column name “dob”.
Cleare cache and check it. You will get magento default date picker.