Copy this file:
\lib\Varien\Data\Form\Element\Date.php
to the local code pool:
app/code/local/Varien\Data\Form\Element\Date.php
Now you can customize the calendar setup.
To add an option for disabling past dates, change getElementHtml() function as below:
/**
* Output the input field and assign calendar instance to it.
* In order to output the date:
* - the value must be instantiated (Zend_Date)
* - output format must be set (compatible with Zend_Date)
*
* MMA-20141125-added new option: disable_past_dates => boolean
* @return string
*/
public function getElementHtml()
{
$this->addClass('input-text');
$html = sprintf(
'<input name="%s" id="%s" value="%s" %s style="width:110px !important;" />'
.' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
$this->getName(), $this->getHtmlId(), $this->_escape($this->getValue()), $this->serialize($this->getHtmlAttributes()),
$this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '')
);
$outputFormat = $this->getFormat();
if (empty($outputFormat)) {
throw new Exception('Output format is not specified. Please, specify "format" key in constructor, or set it using setFormat().');
}
$displayFormat = Varien_Date::convertZendToStrFtime($outputFormat, true, (bool)$this->getTime());
//MMA custom code
$disablePastDates = $this->getDisablePastDates();
$calendarJs = '
<script type="text/javascript">
//<![CDATA[
Calendar.setup({
inputField: "%s",
ifFormat: "%s",
showsTime: %s,
button: "%s_trig",
align: "Bl",
singleClick : true';
if($disablePastDates)
$calendarJs .= ',disableFunc: function(date) {
var now= new Date();
if(date.getFullYear() < now.getFullYear()) { return true; }
if(date.getFullYear() == now.getFullYear()) { if(date.getMonth() < now.getMonth()) { return true; } }
if(date.getMonth() == now.getMonth()) { if(date.getDate() < now.getDate()) { return true; } }
}';
$calendarJs .= '});//]]></script>';
$html .= sprintf($calendarJs,
$this->getHtmlId(), $displayFormat,
$this->getTime() ? 'true' : 'false', $this->getHtmlId()
);
$html .= $this->getAfterElementHtml();
return $html;
}
Then, in your blocks, when adding a date field, you can specify in the addField options array:
'disable_past_dates' => true
If you want to change the align of the calendar, I’ve found that possible values are these, but written with lower second letter:
http://yuilibrary.com/yui/docs/api/classes/WidgetPositionAlign.html#property_BL
If you want to add a secondary date field input to a specific mass action:
$dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$this->getMassactionBlock()->addItem('repair_date',
array(
'label'=> $this->__('Set Date'),
'url' => $this->getUrl('*/*/massRepairDate', array('_current'=>true)),
'additional' => array(
'visibility_set_date' => array( //'visibility_set_date' will be the ID of the date input field
'name' => 'visibility_set_date',
'type' => 'date',
'class' => 'required-entry',
'label' => $this->__('Select Date'),
'format' => $dateFormatIso,
'input_format' => $dateFormatIso,
'gmtoffset' => true,
'image' => '/skin/adminhtml/default/default/images/grid-cal.gif',
'disable_past_dates' => true //this will work if you do the above customizations
)
)
)
);




