Reputation: 35
I am trying to disable specific dates (multiple amounts) from datepicker in my online booking script. I have looked through handfuls of Google searches for a solution but none of them seem to work with my script.
Edit: When I say it doesn't work with this script, I mean either all of the dates become disabled or the datepicker doesn't appear.
We previously wanted to disable Sundays and BG101 helped us accomplish (thank you) this with
$this.datepicker($.extend(dOpts, {
beforeShowDay: function(date) {
return [(date.getDay() != 0), '']; // 0 => Sunday
}
}));
Any help and guidance would be deeply appreciated.This turned into a 8 hour project :(
Here is my script: http://pastebin.com/xDFxXUeJ
Upvotes: 2
Views: 5353
Reputation: 15164
Sorav Garg's answer is correct for excluding specific days, though you will need to combined the exclude of sunday also:-
Here is an example of excluding all of next week:-
var exclude = ["16-11-2015", "17-11-2015", "18-11-2015", "19-11-2015", "20-11-2015", "21-11-2015"]
$('#calendar').datepicker({
beforeShowDay: function(date) {
var day = jQuery.datepicker.formatDate('dd-mm-yy', date);
return [!~$.inArray(day, exclude) && (date.getDay() != 0)];
}
});
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/redmond/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<input id="calendar" />
Upvotes: 3
Reputation: 1067
@mark please try this it will work --
for bootstrap datepicker --
http://jsfiddle.net/Lr3taznx/35/
for jquery datepicker --
http://jsfiddle.net/CxNNh/2568/
Upvotes: 1