【发布时间】:2018-01-05 14:43:39
【问题描述】:
我在我的应用程序中使用“flatpickr”作为日期时间选择器。此日期选择器允许选择多个日期,但在阅读文档后,我找不到任何方法来限制所选日期的最大数量。
jquery:
$('#gig_date_multi').flatpickr({
"mode": "multiple",
"locale": "<%= I18n.locale %>",
minDate: new Date(),
enableTime: true,
time_24hr: true,
minuteIncrement: 15,
onChange: function(selectedDates, dateStr, instance) {
var array = selectedDates;
if (array.length >= 3) {
console.log("YOU HAVE REACHED YOUR LIMIT")
} else {
console.log("YOU CAN STILL SELECT MORE DATES")
}
var newHTML = [];
$.each(array, function(index, value) {
var formatted = moment(value).format("HH:mm - dddd Do MMMM YYYY");
newHTML.push('<span>' + formatted + '</span>');
});
$(".multi-dates").html(newHTML.join(""));
}
});
Here when 3 dates are selected the console outputs "YOU HAVE REACHED YOUR LIMIT" and I was thinking maybe I could disable all dates (apart from previously selected ones) when this occurs.
Flatpickr 有一个 disable 和 enable 函数,但我不确定如何将它集成到代码中...我是 jquery 初学者。
文档显示了这两种方法;
{
"disable": [
function(date) {
// return true to disable
return (date.getDay() === 5 || date.getDay() === 6);
}
],
"locale": {
"firstDayOfWeek": 1 // start week on Monday
}
}
和
{
enable: ["2017-03-30", "2017-05-21", "2017-06-08", new Date(2017, 8, 9) ]
}
【问题讨论】:
-
这些是可以选择的日期范围还是个别日期?
-
@Cue 这些是可以选择的个别日期。
标签: jquery datepicker flatpickr