-
Notifications
You must be signed in to change notification settings - Fork 31
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
Constrain view to specified from/to years #19
base: master
Are you sure you want to change the base?
Changes from 2 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 |
---|---|---|
|
@@ -43,6 +43,7 @@ function Calendar(date) { | |
this.days.on('month', this.menuChange.bind(this, 'month')); | ||
this.show(date || new Date); | ||
this.days.on('change', function(date){ | ||
if (self.invalidDate(date)) { return }; | ||
self.emit('change', date); | ||
}); | ||
} | ||
|
@@ -92,6 +93,7 @@ Calendar.prototype.select = function(date){ | |
*/ | ||
|
||
Calendar.prototype.show = function(date){ | ||
if (this.invalidDate(date)) { return this }; | ||
this._date = date; | ||
this.days.show(date); | ||
return this; | ||
|
@@ -109,6 +111,8 @@ Calendar.prototype.show = function(date){ | |
Calendar.prototype.showYearSelect = function(from, to){ | ||
from = from || this._date.getFullYear() - 10; | ||
to = to || this._date.getFullYear() + 10; | ||
this._from = from; | ||
this._to = to; | ||
this.days.yearMenu(from, to); | ||
this.show(this._date); | ||
return this; | ||
|
@@ -194,3 +198,23 @@ Calendar.prototype.menuChange = function(action){ | |
this.emit('view change', date, action); | ||
return this; | ||
}; | ||
|
||
/** | ||
* Check if date is outside the from/to years specified. | ||
* | ||
* @return {Boolean} | ||
* @api private | ||
*/ | ||
|
||
Calendar.prototype.invalidDate = function(date) { | ||
var year = date.getFullYear(); | ||
|
||
// allow for reversed range with from > to | ||
var from = this._to < this._from ? this._to : this._from; | ||
var to = this._to < this._from ? this._from : this._to; | ||
|
||
if ((from && year < from) || (to && year > to)) { | ||
return true; | ||
} | ||
return false; | ||
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. this could be 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. Much better - thanks. Will fix shortly. |
||
} |
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.
i dont think we need reversing really, it would be pretty weird to specify them in reverse IMO
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.
I am using calendar in a colinf/datepicker. And for example when selecting date of birth, it is a common requirement especially when dealing with children to list years in reverse starting from current year.
BTW reversing can only be invoked if you accept my pull request (or an improved version of it!) to component/range.
Cheers, Colin
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.
ah I see what you mean, that makes sense