【问题标题】:Magento date picker is not working when current date is disable当前日期被禁用时,Magento 日期选择器不工作
【发布时间】:2015-05-07 06:34:00
【问题描述】:

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

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);

仅会禁用前几天。但启用日期可以从日期选择器中选择。

请帮帮我..

【问题讨论】:

标签: javascript php magento datepicker


【解决方案1】:

您无需更改您的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; }
 }

【讨论】:

    【解决方案2】:

    我终于找到了解决方案。 在 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;
    

    问题已经解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-05
      相关资源
      最近更新 更多