Magento date picker is not working when current date is disable

Magento date picker is not working when current date is disable

October 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento date picker is not working when current date is disable

Troubleshooting Magento Date Picker Disabling Issues

Are you facing difficulties with your Magento date picker where it won’t allow you to select enabled dates even though previous days are correctly disabled? You’re not alone in this common challenge faced by many developers.

The issue likely lies in the way you’ve implemented the disableFunc function. Let’s break down what might be going wrong and how to resolve it.

Understanding the Current Implementation

You’ve used the following code to disable dates:

disableFunc: function(date)  {                                  
    var now = new Date(Date.now() + 48 * 60 * 60 * 1000);
    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; } }
                },

The now variable is set to a date 48 hours into the future. This ensures that any dates before this time are disabled.

The Problem with Your Approach

The issue arises when you try to select a date that is enabled but occurs after the current date and within the next 48 hours. In this situation, you’re essentially disabling dates including those in the immediate future.

If you change now to represent the current date using var now = new Date();, it correctly disables only past dates. However, this still leaves a gap where enabled dates are unselectable due to the 48-hour window originally defined.

The Solution: Adjusting the Disable Window

To fix this, you need to adjust your disable window so that it doesn’t include dates within the next few hours (or however long you want). Here’s an updated version:

disableFunc: function(date)  {
    var now = new Date();
    if(now.getHours() < 12 && date.getHours() < 12) { return true; }
    // Rest of your code...
},

In this example, we’re disabling dates where both the current hour and the selected date’s hour are less than 12 (AM). This effectively disables all past dates but keeps future dates accessible.

Best Practices for Magento Date Picker

Remember to follow these best practices when working with Magento date picker:

  • Always test your changes thoroughly in different scenarios, including edge cases.
  • Keep your JavaScript code organized and easy to maintain.
  • Ensure you’re using the correct version of jQuery UI or other libraries required by the date picker.

For more detailed guides on Magento development, I highly recommend exploring the resources available at Laravel Company. They provide comprehensive tutorials and best practices for working with Magento efficiently and effectively.

Conclusion

In summary, to resolve the issue where enabled dates in a Magento date picker are unselectable after disabling past dates:

  1. Identify which dates you’re accidentally disabling.
  2. Adjust your disable function logic to exclude the desired range of valid dates.
  3. Test your changes across various scenarios to ensure all required functionality remains intact.

With these steps, you should now be able to use your Magento date picker without encountering this issue. Happy coding!

Errors JavaScript

Our network