Magento – How to we disable past dates from date input field in admin

admindatepickermagento-1.9

I am using below code to add date field in one of the admin forms.

$fieldset->addField('newsletter_date', 'date', array(
    'label'     => Mage::helper('masters')->__('Send At'),
    'class'     => 'required-entry',
    'required'  => true,
    'name'      => 'newsletter_date',
    'format' => 'MM/dd/yyyy HH:mm',
    'image' => $this->getSkinUrl('images/grid-cal.gif'),
    'time' =>   'true'
));

How I can disable past dates from newsletter_date field?

Best Answer

You can't out of the box. But you can implement your own validation based on Magento's js/prototype/validation.js.

Inchoo has a good blogpost about this.

After Magentos validation.js is added you can just add your own and then use the CSS class to validate the field right before the form submit.

Validation.add('validate-email', 'Please enter a valid Gmail address. For example johndoe@gmail.com.', function(v) {
    return Validation.get('IsEmpty').test(v) || /^([a-zA-Z0-9]+[a-zA-Z0-9._%-]*@gmail\.com)$/i.test(v)
})

Example is copied from the inchoo article, I'm not good with JS, so I'll let the implementation of $date > now() up to you :-)