Skip to content

Commit

Permalink
Add isCustomDate to apply custom CSS class to individual dates
Browse files Browse the repository at this point in the history
  • Loading branch information
dangrossman committed May 25, 2016
1 parent 0fe9011 commit c8ed27c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@
if (typeof options.isInvalidDate === 'function')
this.isInvalidDate = options.isInvalidDate;

if (typeof options.isCustomDate === 'function')
this.isCustomDate = options.isCustomDate;

if (typeof options.alwaysShowCalendars === 'boolean')
this.alwaysShowCalendars = options.alwaysShowCalendars;

Expand Down Expand Up @@ -509,6 +512,10 @@
return false;
},

isCustomDate: function() {
return false;
},

updateView: function() {
if (this.timePicker) {
this.renderTimePicker('left');
Expand Down Expand Up @@ -806,6 +813,15 @@
if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate)
classes.push('in-range');

//apply custom classes for this date
var isCustom = this.isCustomDate(calendar[row][col]);
if (isCustom !== false) {
if (typeof isCustom === 'string')
classes.push(isCustom);
else
Array.prototype.push.apply(classes, isCustom);
}

var cname = '', disabled = false;
for (var i = 0; i < classes.length; i++) {
cname += classes[i] + ' ';
Expand Down
5 changes: 5 additions & 0 deletions website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,11 @@ <h2>Options</h2>
calendars before they are displayed, and may return true or false to indicate whether
that date should be available for selection or not.
</li>
<li>
<code>isCustomDate</code>: (function) A function that is passed each date in the two
calendars before they are displayed, and may return a string or array of CSS class names
to apply to that date's calendar cell.
</li>
<li>
<code>autoUpdateInput</code>: (boolean) Indicates whether the date range picker should
automatically update the value of an <code>&lt;input&gt;</code> element it's attached to
Expand Down

0 comments on commit c8ed27c

Please sign in to comment.