Have not done this myself, so this is a guide to get you in the right direction.
the calendar used by magento is located here : /js/calendar/calendar.js, and from its header comments, you will find it is done by http://www.dynarch.com/, and the docs is located here : http://www.dynarch.com/jscal
You will see there is built in functionality (via a callback) to disable dates. (http://www.dynarch.com/jscal/#sec8)
You can also disable individual dates by supplying a callback function
which receives a JS date object and returns true if that date must be
disabled, or false otherwise. .....suppose you have in your
database a list of dates that should be disabled, just convert them
to numeric value and build up a hash table, then your disabled()
handler can very conveniently return true for them:
(sound just like what you want/have ;) )
var DISABLED_DATES = {
20090502: true,
20090505: true,
20090510: true,
20090511: true
};
Calendar.setup({
cont : "sample3",
disabled : function(date) {
date = Calendar.dateToInt(date);
return date in DISABLED_DATES;
}
});
To extend magento calendar creation, you need to create your own class, which extends the core Varien_Data_Form_Element_Date
class, which will allow you to adjust the setup for the calendar, and include your dates. You will need to override the getElementHtml()
method, which contains the calandar setup script code.
$html .= sprintf('
<script type="text/javascript">
//<![CDATA[
Calendar.setup({
inputField: "%s",
ifFormat: "%s",
showsTime: %s,
button: "%s_trig",
align: "Bl",
singleClick : true
});
//]]>
</script>',
$this->getHtmlId(), $displayFormat,
$this->getTime() ? 'true' : 'false', $this->getHtmlId()
);
and include the callback and dates you have, as per the calendar docs.
I am not sure how you are displaying the calendars in your site, but one way to use the custom class in a form is to create a custom form element as such:
$this->getForm()->addType('customDate','ProxiBlue_GiftPromo_Data_Form_Element_Date');
Hope this helps you in the right direction.
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.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 :-)