【问题标题】:Disable all sundays except mother day禁用除母亲节以外的所有星期日
【发布时间】:2021-05-09 20:04:15
【问题描述】:

我想在 flatpickr 中禁用所有星期天,这样可以正常工作。但现在我想定义一些例外,例如母亲节。这是我的代码,但 if-block 将始终执行,我仍然无法选择母亲节。

   // Mothers Day -> dd.mm.yyyy
   const d = new Date();
   d.setMonth(4); // May
   d.setDate(8); // May 8 is the earliest possible date
   // while not a sunday, move to next day
   while (d.getUTCDay()) d.setDate(d.getDate() + 1);
   const motherDayDate = new Intl.DateTimeFormat('de-DE', { day: "2-digit", month: "2-digit", year: "numeric"}).format(d);

  $(".datePicker").flatpickr({
    enableTime: false,
    dateFormat: "d.m.Y",
    minDate: "today",
    "locale": {
        "firstDayOfWeek": 1
    },
    "disable": [
        function(date) {
            //  motherDayDate = e.g. 09.05.2021
            if (moment(date).format("DD.MM.YYYY") === motherDayDate){
                alert ("mother");
                return true;
            }
            
            // 0 = Sunday
            return (date.getDay() === 0);
        }
    ]
});

【问题讨论】:

  • motherDayDate 似乎没有在任何地方设置。如果您正在设置它,请将其包含在您的示例中

标签: javascript html flatpickr


【解决方案1】:

我对 flatpickr 不是很熟悉,但也许您应该在代码 alert("mother"); 下方返回 false

(如果我有足够的声誉,我会将此作为评论发布。不过希望这会有所帮助!)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-21
    • 1970-01-01
    • 2018-05-14
    • 2012-05-20
    • 1970-01-01
    • 2020-10-08
    • 2011-04-12
    • 2017-10-11
    相关资源
    最近更新 更多