选择最少的一天

时间:2018-10-01 09:13:31

标签: jquery flatpickr

我将flatpickr用作在线预订的日期选择器,我正在寻找设置最低天数来选择预订的选项或功能。但是不可能找到正确的论据。我已经从执行此代码开始,但是我在最少的几天内被屏蔽。

function pad(s) { return (s < 10) ? '0' + s : s; }

if (typeof id_product !== 'undefined') {
    $('.add > button').hide();
console.log(minimum_retail);
    $('#datepicker').flatpickr({
        min: minimum_retail,
        inline: true,
        locale: 'fr',
        mode: 'range',
        minDate: "today",
        dateFormat: "d-m-Y",
        appendTo: document.getElementById("datePicker"),
        disable: unavailableDates,
        onDayCreate: function (dObj, dStr, fp, dayElem) {
            var d = new Date(+dayElem.dateObj);
            var temp = [pad(d.getDate()), pad(d.getMonth() + 1), d.getFullYear()].join('-');

            if (greetings.indexOf(temp) !== -1) {
                dayElem.className += " greetings";
            }
        },
        onChange: function (selectedDates, dateStr, instance) {
            console.log(instance);
                if (selectedDates.length == 2 && selectedDates[0] != selectedDates[1]) {
                    var allPresent = true;

                    while ([pad(selectedDates[0].getDate()), pad(selectedDates[0].getMonth() + 1), selectedDates[0].getFullYear()].join('-') != [pad(selectedDates[1].getDate()), pad(selectedDates[1].getMonth() + 1), selectedDates[1].getFullYear()].join('-')) {
                        var days = [pad(selectedDates[0].getDate()), pad(selectedDates[0].getMonth() + 1), selectedDates[0].getFullYear()].join('-');
                        if (greetings.indexOf(days) === -1) {
                            allPresent = false;
                        }
                        selectedDates[0].setDate(selectedDates[0].getDate() + 1);
                    }
                    if (allPresent === true) {
                        $('.add_to_cart').hide();
                        $('#button_souhait').show();
                    } else {
                        $('.add_to_cart').show();
                        $('#button_souhait').hide();
                    }
                } else {
                    instance.set('minDate', 'today')
                }

            $('#datepicker').css({'background': '#E51937', 'color': 'white', 'padding': '5px'})
        },
    });
}

感谢您的帮助。

0 个答案:

没有答案