Setting the boot date (Bootstrap datepicker) to block certain dates (holidays)

Has anyone figured out how to set datepicker to not display specific dates (like July 4th)? It would seem that this can be done using beforeShowDay, but I'm not sure.

+4
source share
3 answers

http://jsfiddle.net/Lr3taznx/

//a array of dates that should be blocked
var forbidden=['12/25/2014','12/24/2014']

$('#datepicker').datepicker({
    beforeShowDay:function(Date){
        //
        var curr_day = Date.getDate();
        var curr_month = Date.getMonth()+1;
        var curr_year = Date.getFullYear();        
        var curr_date=curr_month+'/'+curr_day+'/'+curr_year;        

        if (forbidden.indexOf(curr_date)>-1) return false;        
    }
})

OR

http://jsfiddle.net/zsqvjvkd/1/

var forbidden=['2014-12-25','2014-12-24']

$('#datepicker').datepicker({
    beforeShowDay:function(Date){
        var curr_date = Date.toJSON().substring(0,10);

        if (forbidden.indexOf(curr_date)>-1) return false;        
    }
})
+3
source

With version 1.3.1+, you can simply use the option datesDisabled: http://bootstrap-datepicker.readthedocs.org/en/latest/options.html#datesdisabled

+2
source

, Twitter Bootstrap DatePicker: , moment.js:

var disabledDates = ['2018-01-07', '2018-01-27']

beforeShowDay: function (Date) {        
   $('#datepicker').datepicker({
        var date = moment(Date).format('YYYY-MM-DD');
        if (disabledDates.indexOf(curr_date) > -1) return false;
   });
},
0
source

Source: https://habr.com/ru/post/1568922/


All Articles