Disable some days in magento calendar

Disable some days in magento calendar

October 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Disable some days in magento calendar

Disabling Specific Days in Magento Calendar

The Magento calendar widget is a powerful tool for date selection on your website, but sometimes you may need to restrict certain days. Let’s explore how to disable specific days like Mondays or dates within a certain range.

Disabling All Mondays

To disable all Mondays in the calendar, we’ll use the onShow event of the calendar and check each day before allowing selection. Here’s an example:

<script type="text/javascript">
//<![CDATA[
Calendar.setup({
    inputField: '_dob',
    ifFormat: '%m/%e/%y',
    button: '_dob_trig',
    align: 'Bl',
    singleClick: true,
    onShow: function (cal) {
        var now = new Date();
        for (var i = 0; i < cal.days.length; i++) {
            if (cal.days[i].date.getDay() === 1) { // 1 represents Monday
                cal.days[i].className = 'disabled';
            }
        }
    }
});
//]]>
</script>

In this script, the onShow function runs when the calendar is displayed. It iterates through each day and checks if it’s a Monday (represented by getDay() === 1). If so, it sets the className to ‘disabled’, which disables user interaction with that date.

You can add this script to your Magento template file where you want to display the calendar.

Disabling Dates Before or After Today

To disable dates before a certain number of days from today or after today, we’ll use a similar approach:

<script type="text/javascript">
//<![CDATA[
Calendar.setup({
    inputField: '_dob',
    ifFormat: '%m/%e/%y',
    button: '_dob_trig',
    align: 'Bl',
    singleClick: true,
    onShow: function (cal) {
        var now = new Date();
        for (var i = 0; i < cal.days.length; i++) {
            if (cal.days[i].date.getTime() <= now.setDate(now.getDate() - 3) || // disable dates before today + 3 days
                cal.days[i].date.getTime() > now.setDate(now.getDate() + 7)) { // disable dates after today + 7 days
                cal.days[i].className = 'disabled';
            }
        }
    }
});
//]]>
</script>

In this script, the setDate method is used to calculate the date three or seven days from today. Any date before this threshold or after another threshold (today + 7 days) will be disabled.

Conclusion

Disabling specific days in the Magento calendar requires a bit of JavaScript manipulation using the calendar’s event hooks. By adding an onShow function, we can check each day and disable it if certain conditions are met, such as being a Monday or falling outside a specified date range.

Remember to place these scripts in your Magento template files where you want the calendars to appear. If you’re looking for more advanced calendar customizations, consider contacting a professional development team like those at Laravel Company.

The key is understanding the calendar’s JavaScript API and using it creatively to meet your specific business needs. Happy coding!

API Themes JavaScript CLI

Our network