Created
September 18, 2012 16:23
-
-
Save jafoca/3744085 to your computer and use it in GitHub Desktop.
Restrict the options on a jQueryUI date picker to allow only weekdays at a minimum of 2 business days in the future
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
$(document).ready(function() { | |
$('.date').datepicker({ | |
dateFormat: 'yy-mm-dd', | |
minDate : setRestrictedDates(), | |
beforeShowDay: $.datepicker.noWeekends | |
}); | |
}); | |
function setRestrictedDates(){ | |
var today = new Date(); | |
//default to second business day | |
var offset = 2; | |
switch(today.getDay()) | |
{ | |
//sunday -> wednesday | |
case 0: | |
offset = 3; | |
break; | |
//thursday -> monday | |
case 4: | |
//friday -> tuesday | |
case 5: | |
//saturday -> wednesday | |
case 6: | |
offset = 4; | |
break; | |
} | |
return offset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setRestrictedDates uses a switch statement for read-ability, not sure if this is the 'best' way of doing it.