Skip to content

Commit

Permalink
Add weekdays option to allow specified days only
Browse files Browse the repository at this point in the history
The 'weekdays' option adds the ability to specify which days of the week
are selectable. For example weekdays; [0,6] allows only Saturday or
Sunday to be
selected.
  • Loading branch information
GreyHead committed Oct 13, 2012
1 parent 74dc494 commit bd42b5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -104,6 +104,7 @@ All the options of the Picker and Picker.Attach classes, and:
- minDate: (*Date instance*, *string*, defaults to `null`) Minimum date allowed to pick. Blocks anything before.
- maxDate: (*Date instance*, *string*, defaults to `null`) Maximum date allowed to pick. Blocks anything after.
- availableDates: (*object*, defaults to `null`) When only a few dates should be selectable. An object like `{2011: {1: [19, 29, 31], 3: [5, 19, 24]}}` with all the dates (year -> months -> days).
- weekdays: (*object*, defaults to `null`) When only specified days of the week should be selectable. An object like `[1, 2, 4, 5]` with the selectable weekdays.
- invertAvailable: (*boolean*, defaults to `false`) Invert the `availableDates` option.
- format: (*string*, defaults to the default localized format) The format to output into the input field. Uses [Date.format](http://mootools.net/docs/more/Types/Date#Date:format)
- timePicker: (*boolean*, defaults to 1 `false`) Enable/disable timepicker functionality. Hours/Minutes values can be changed using the scrollwheel.
Expand Down
12 changes: 10 additions & 2 deletions Source/Picker.Date.js
Expand Up @@ -22,6 +22,7 @@ this.DatePicker = Picker.Date = new Class({
maxDate: new Date('3/4/2011'), // same as minDate
availableDates: {}, //
invertAvailable: false,
weekdays: null, // null allows all days, a subset of [0, 1, 2, 3, 4, 5, 6] allows only selected days e.g [0, 6] allows Saturday and Sunday only
format: null,*/

Expand Down Expand Up @@ -608,9 +609,12 @@ var isUnavailable = function(type, date, options){
var minDate = options.minDate,
maxDate = options.maxDate,
availableDates = options.availableDates,
weekdays = options.weekdays,
year, month, day, ms;

if (!minDate && !maxDate && !availableDates) return false;
if ( typeof availableDates == 'undefined' ) {
availableDates = null;
}
if (!minDate && !maxDate && !availableDates && !weekdays) return false;
date.clearTime();

if (type == 'year'){
Expand Down Expand Up @@ -653,8 +657,12 @@ var isUnavailable = function(type, date, options){
year = date.get('year');
month = date.get('month') + 1;
day = date.get('date');
weekday = date.getDay();

var dateAllow = (minDate && date < minDate) || (maxDate && date > maxDate);
if ( weekdays !== null ) {
dateAllow = dateAllow || !weekdays.contains(weekday);
}
if (availableDates != null){
dateAllow = dateAllow
|| availableDates[year] == null
Expand Down

0 comments on commit bd42b5b

Please sign in to comment.