Last active
August 29, 2015 14:18
-
-
Save xeviknal/52687513fa8c7236bd20 to your computer and use it in GitHub Desktop.
Disable ranges of time in jQuery DatePicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var holidays = [ ['04/5/2015', '04/11/2015'], ['4/26/2015', '4/28/2015'], ['4/30/2015', '5/8/2015'] ]; | |
function highlightDays(date) { | |
for (var i = 0; i < holidays.length; i++) { | |
var in_range = (new Date(holidays[i][0]) <= date) && (new Date(holidays[i][1]) >= date); | |
if (in_range) { | |
return [false]; | |
} | |
} | |
return [true]; | |
} | |
$(function () { | |
$("#dp").datepicker({ | |
minDate: 0, | |
dateFormat: 'mm/dd/yy', | |
inline: true, | |
numberOfMonths: [1, 2], | |
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], | |
beforeShowDay: highlightDays, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Improved a piece of code from http://jsfiddle.net/CxNNh/78/
Not focused on performance neither style!