JQuery Datepicker: limiting weekly date picker

Is it possible to modify the jQuery UI Datepicker to allow users to select, for example, Mondays?

+8
javascript jquery user-interface
source share
5 answers

Here you go: Mondays cannot be selected:

$(document).ready(function(){ $('input').datepicker({beforeShowDay: function(date){ return [date.getDay() != 1, '']; }}); }); 

An example of functioning that you can play with here: http://jsfiddle.net/RaYZ5/19/ .

API Documentation: http://docs.jquery.com/UI/Datepicker#event-beforeShowDay

+12
source share

Previous posts were exactly correct. but more specifically with respect to Monday's impressions only:

 $('#date').datepicker({ beforeShowDay: function (a){a=a.getDay();return[a==1,""]} }); 
+7
source share

Yes, it looks like this:

 $("#datepicker").datepicker({ beforeShowDay: $.datepicker.noWeekends }); 

You need to write a function instead of $ .datepicker.noWeekends to do what you need.

http://docs.jquery.com/UI/Datepicker/noWeekends

+1
source share

If you want to use VERY FLEXIBLE and deactivate any date you want for a certain period of time, you can do the following:

$ dt_str are the dates you want to disable. You can structure it using PHP, for example, and get your dates from the database.

When the DOM boots, disableDates () is called and the magic happens.

 var avDays = <?php echo $dt_str ?>; <script type='text/javascript'> $(document).ready( function(){ // Datepicker $('.datepicker_event').datepicker( { inline: true, numberOfMonths: 2, beforeShowDay: disableDates }); } ) function disableDates(date) { var isAvailable = false ; // Find the days to deactivate if (avDays != null) { for (i = 0; i < avDays.length; i++) { if (date.getMonth() == avDays[i][0] - 1 && date.getDate() == avDays[i][1] && date.getFullYear() == avDays[i][2]) { isAvailable = true; } } } if (isAvailable) return [true, 'av_day'] ; else return [false, '']; } </script> 
+1
source share

The easiest way to find out:

 $("#datepicker").datepicker({ beforeShowDay: function(date) { var day = date.getDay(); return [(day > 0 && day < 6), '']; } }); 
0
source share

All Articles