当当前日期被禁用时,Magento 日期选择器不工作

Magento date picker is not working when current date is disable

我在前端使用 magento date picker 表示 select 产品交货日期。我想禁用以前的日期,今天和明天。为此,我使用:

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; } }
                },

dates are disabled..OK。但是I can't select the enabled dates from date picker.

如果我用

var now = new Date(); 

而不是

var now = new Date(Date.now() + 48 * 60 * 60 * 1000);

只有前几天会禁用。但是启用的日期可以 select 来自日期选择器。

请帮帮我..

终于找到解决办法了。 在js/calendar/calendar.js 有一个变量currentDateEl。默认是null。你只需要设置 this.currentDateElcurrent date.

var currentDate = new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
var dmy =  day + "/" + month + "/" + year;
this.currentDateEl = dmy;

现在问题已经解决了。

您不需要更改 calendar.js 文件。只需在 disableFunc 中添加 currentDateEl,例如:

 disableFunc: function(date)  {
                var now = new Date();
                this.currentDateEl = now.getDate();
                if(date.getFullYear() < now.getFullYear()) { return true; }
                if(date.getFullYear() == now.getFullYear() && date.getMonth() < now.getMonth()) { return true; }
                if(date.getMonth() == now.getMonth() && date.getDate() < now.getDate()) { return true; }
 }