如何在 flatpickr.js 中同时使用启用和禁用属性?
How to use enable and disable properties together in flatpickr.js?
我无法在 flatpickr.js 中同时使用启用和禁用属性。实际上 enable 属性 返回的是应该启用的日期范围,但我想禁用特定日期,比如那些启用日期范围内的周末。
datePickerInput.flatpickr({
clickOpens: false,
disableMobile: 'true', // Do not render mobile version UI
closeOnSelect: false,
defaultDate: null,
enable: [getEnableDays()],
disable: [
function (date) {
return (date.getDay() === 0 || date.getDay() === 6);
}
],
locale: {
"firstDayOfWeek": 1
}
});
getEnableDays: function () {
var me = this;
var maxDate = '2090-12-25T16:16:22.585Z';
var minDate = '1900-12-24T16:16:22.585Z';
var fromDate = minDate;
var toDate = maxDate;
if (me.disableDays) {
fromDate = me.isPrevDaysDisable ? me.calculatedDate.toISOString().slice(0, 10) : 'today';
toDate = !me.isPrevDaysDisable ? me.calculatedDate.toISOString().slice(0, 10) : 'today';
}
return {
from: fromDate,
to: toDate,
};
},
您不能同时使用禁用和启用,但这里介绍了如何使用 onDayCreate 实现禁用周末功能。
onDayCreate: function (dObj, dStr, fp, dayElem) {
if (dayElem.dateObj.getDay() === 0 || dayElem.dateObj.getDay() === 6) {
dayElem.className += " flatpickr-disabled nextMonthDayflatpickr-disabled";
}
},
我无法在 flatpickr.js 中同时使用启用和禁用属性。实际上 enable 属性 返回的是应该启用的日期范围,但我想禁用特定日期,比如那些启用日期范围内的周末。
datePickerInput.flatpickr({
clickOpens: false,
disableMobile: 'true', // Do not render mobile version UI
closeOnSelect: false,
defaultDate: null,
enable: [getEnableDays()],
disable: [
function (date) {
return (date.getDay() === 0 || date.getDay() === 6);
}
],
locale: {
"firstDayOfWeek": 1
}
});
getEnableDays: function () {
var me = this;
var maxDate = '2090-12-25T16:16:22.585Z';
var minDate = '1900-12-24T16:16:22.585Z';
var fromDate = minDate;
var toDate = maxDate;
if (me.disableDays) {
fromDate = me.isPrevDaysDisable ? me.calculatedDate.toISOString().slice(0, 10) : 'today';
toDate = !me.isPrevDaysDisable ? me.calculatedDate.toISOString().slice(0, 10) : 'today';
}
return {
from: fromDate,
to: toDate,
};
},
您不能同时使用禁用和启用,但这里介绍了如何使用 onDayCreate 实现禁用周末功能。
onDayCreate: function (dObj, dStr, fp, dayElem) {
if (dayElem.dateObj.getDay() === 0 || dayElem.dateObj.getDay() === 6) {
dayElem.className += " flatpickr-disabled nextMonthDayflatpickr-disabled";
}
},