0

I'm trying to disable certain days of the calendar, but I can not.

I'm using this datepicker https://github.com/eternicode/bootstrap-datepicker/blob/master/docs/index.rst.

The javascript code I have is this, I work all I need except the days you want to disable.

var disabledDays = ['11/29/2013', '11/27/2013', '11/28/2013']; function daysDisabled(date) { for (var i = 0; i < disabledDays.length; i++) { if (new Date(disabledDays[i]).toString() == date.toString()) { return [false, '']; } } return [true, '']; } $('.datepicker').datepicker({ format: 'dd-mm-yyyy', todayHighlight: true, autoclose: true, weekStart: 1, startDate: '0d', language: 'es', beforeShowDay: daysDisabled }) 
2
  • you're returning an array while the docs say that you should return either a plain boolean, a string with a CSS class for the cell, or an OBJECT with the format {enabled:true|false,classes:"cssclassforthecell","tooltip":"tooltiptextforthecell"}. So you can return just the bool value. Commented Nov 19, 2013 at 13:51
  • can you create fiddle for same?? Commented Nov 19, 2013 at 13:52

2 Answers 2

2

just modify your function like this:

function daysDisabled(date) { for (var i = 0; i < disabledDays.length; i++) { if (new Date(disabledDays[i]).toString() == date.toString()) { return false; } } return true; } 
Sign up to request clarification or add additional context in comments.

1 Comment

that failure dumber. Thank you very much, it was just what I needed
0

Created Fiddle for you.

Working Fiddle

function initComponent(){ /* Date retrait */ $("#dateRetrait").datepicker({ dateFormat: 'dd-mm-yy', minDate: new Date(), beforeShowDay: function(d) { var dmy = (d.getMonth()+1); if(d.getMonth()<9) dmy="0"+dmy; dmy+= "-"; if(d.getDate()<10) dmy+="0"; dmy+=d.getDate() + "-" + d.getFullYear(); console.log(dmy+' : '+($.inArray(dmy, disbleddates))); if ($.inArray(dmy, disbleddates) != -1) { return [false, "","Available"]; } else{ return [true,"","unAvailable"]; } } }); 

1 Comment

thanks for your help, I will review your code, but just needed to disable the days, I will look at your code to add styles.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.