-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suggested fix for #124 #168
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,6 +288,22 @@ | |
type: Date, | ||
value: null | ||
}, | ||
/** | ||
*Array of selectable dates | ||
* (whitelist) | ||
*/ | ||
validDates:{ | ||
type: Array, | ||
value: [] | ||
}, | ||
/** | ||
* Array of not selectable dates | ||
* (blacklist) | ||
*/ | ||
invalidDates:{ | ||
type: Array, | ||
value: [] | ||
}, | ||
/** | ||
* The currently selected month (1-12) | ||
*/ | ||
|
@@ -431,7 +447,7 @@ | |
return cssClass; | ||
}, | ||
_isDisabled: function(day, date) { | ||
return !day || !this._withinValidRange(date); | ||
return !day || !this._withinValidRange(date) || ! this._confirmsToWhiteAndBlacklist(date); | ||
}, | ||
_getMonthClass: function(name, month) { | ||
return name + ' month-' + month.year + '-' + month.month; | ||
|
@@ -628,6 +644,7 @@ | |
console.warn('Date outside of valid range: ' + date); | ||
this.date = date = oldValue; | ||
} | ||
|
||
this.currentYear = date.getFullYear(); | ||
this.currentMonth = date.getMonth() + 1; | ||
// Only trigger a notification if there actually is a difference. | ||
|
@@ -637,7 +654,7 @@ | |
this._updateSelection(); | ||
}, | ||
_tapDay: function(event) { | ||
if (!this._withinValidRange(event.model.item.date)) { | ||
if (!this._withinValidRange(event.model.item.date) || !this._confirmsToWhiteAndBlacklist(event.model.item.date)) { | ||
return false; | ||
} | ||
var item = event.model.item; | ||
|
@@ -652,7 +669,27 @@ | |
}, | ||
_withinValidRange: function(date) { | ||
if (this._isValidDate(date)) { | ||
return (!this.minDate || date >= this.minDate) && (!this.maxDate || date <= this.maxDate); | ||
return (!this.minDate || date >= this.minDate) && (!this.maxDate || date <= this.maxDate); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove double space |
||
} | ||
return false; | ||
}, | ||
|
||
_confirmsToWhiteAndBlacklist: function(date){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Collapse these 3 into:
So we aren't biting the cost of always checking both lists, and checking for a valid date 3 times when we don't have to. |
||
if(this._isValidDate(date)) { | ||
var result = !this._isInBlacklist(date) && this._isInWhitelist(date); | ||
return result; | ||
} | ||
return false; | ||
}, | ||
_isInWhitelist: function(date){ | ||
if(this.validDates && this.validDates.length > 0 && this._isValidDate(date)) { | ||
return this.validDates.indexOf(this.dateFormat(date,'YYYY-MM-DD')) >= 0; | ||
} | ||
return true; | ||
}, | ||
_isInBlacklist: function(date){ | ||
if(this.invalidDates && this.invalidDates.length > 0 && this._isValidDate(date)) { | ||
return this.invalidDates.indexOf(this.dateFormat(date,'YYYY-MM-DD')) >= 0; | ||
} | ||
return false; | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
Format must be String YYYY-MM-DD
here as well as oninvalidDates
so it's documented for people using this element stand-alone.