php developer php developer - 6 months ago 76
Javascript Question

Bootstrap datepicker disabled specific dates

I want to disabled some specific dates in bootstrap datepicker. So how can i achieve this?
I tried many code but doesn't work.

My code:

var disabled_dates = ["24/05/2016","25/05/2016"];
$("#datepicker").datepicker({
language: "pl",
autoclose: true,
//removed line: startDate: '+1d',
weekStart: 1,
default: 'dd/mm/yyyy',
beforeShowDay: function(date){
var formattedDate = $.fn.datepicker.DPGlobal.formatDate(date, 'dd/mm/yyyy', 'pl');
if ($.inArray(formattedDate.toString(), disabled_dates) != -1){
return {
enabled : false
};
}
return;
}
});


Its return following error:

TypeError: dates[this.o.language] is undefined in bootstrap.datepicker.js

Answer
var forbidden='['2016/05/04','2016/05/05','2016/05/06']';

                    $(".datepicker").datepicker({
                        format: "dd/mm/yyyy",
                        startDate: "od",
                        todayHighlight: true,
                        todayBtn: true,
                        beforeShowDay:function(date){

                            var dd = date.getDate();
                            var mm = (date.getMonth()+1);
                            var yy = date.getFullYear();

                              if(dd == 1 || dd == 2 || dd == 3 || dd == 4 || dd == 5 || dd == 6 || dd == 7 || dd == 8 || dd == 9){
                                dd = '0'+dd;
                            }
                            if(mm !=11 || mm !=12){
                                mm = '0'+mm;
                            }
                            var curr_date = yy+'-'+mm+'-'+dd;

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

                    })