简体   繁体   中英

Bootstrap DatetimePicker disable specific dates of week ( sunday - Wednesday)

Im using Bootstrap DateTimePicker to show a calender, and i want to remove some days from the calender (disable them)

$(function () {
        $('#datetimepicker1').datetimepicker({
            inline: true,
            format: "dd MM yyyy",
            defaultDate: null,
            disabledDates: function (date) {
                var day = date.getDay();
                return [(day != 1 && day != 2)];
            }
        })
    }).on('dp.change', function (e, selectedDate, $td) {
        //var time = e.date.format("HH:mm:ss");
        //alert(e.date + '  -  ' + time);
        $('.input-field1').val(e.date.format("DD/MM/YYYY"));
        if (check) {
            $('.FormDownDateSelect').slideToggle("fast", function () { });
        }
    });

I tried the code above Special the part with DisabledDates but it dont work. Can someone tell me how to disable some days of the week. Sunday to Wednesday.

Plugin

You could use daysOfWeekDisabled setting described here .

Your code would look somehow like this:

$(function () {
    $('#datetimepicker1').datetimepicker({
        inline: true,
        format: "dd MM yyyy",
        defaultDate: null,
        daysOfWeekDisabled: [0, 6]
    })
}).on('dp.change', function (e, selectedDate, $td) {
    //var time = e.date.format("HH:mm:ss");
    //alert(e.date + '  -  ' + time);
    $('.input-field1').val(e.date.format("DD/MM/YYYY"));
    if (check) {
        $('.FormDownDateSelect').slideToggle("fast", function () { });
    }
});

I belive it will be easier to use beforeShowDay instead of disabledDates function like this:

beforeShowDay: function(date){
    var day = date.getDay();
    if(day != 1 && day != 2){
        return {
            enabled : false
        };
    }
    return;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM