Skip to content
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

freeNav option to navigate out of bound months #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Option | Description
`date` | The calendar shows days and allows you to navigate between months
`dateValidator` | Function to validate that a given date is considered valid. Receives a native `Date` parameter.
`dayFormat` | Format string used to display days on the calendar
`freeNav` | Enables date navigation to months prior to the current month (default: `false`)
`initialValue` | Value used to initialize calendar. Takes `string`, `Date`, or `moment`
`inputFormat` | Format string used for the input field as well as the results of `rome`
`invalidate` | Ensures the date is valid when the field is blurred
Expand Down
14 changes: 8 additions & 6 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function calendar (calendarOptions) {

crossvent.add(back, 'click', subtractMonth);
crossvent.add(next, 'click', addMonth);
crossvent.add(datewrapper, 'click', pickDay);
if (!o.freeNav) crossvent.add(datewrapper, 'click', pickDay);

function renderMonth (i) {
var month = dom({ className: o.styles.month, parent: datewrapper });
Expand Down Expand Up @@ -310,9 +310,11 @@ function calendar (calendarOptions) {
var direction = op === 'add' ? -1 : 1;
var offset = o.monthsInCalendar + direction * getMonthOffset(lastDayElement);
refCal[op](offset, 'months');
bound = inRange(refCal.clone());
ref = bound || ref;
if (bound) { refCal = bound.clone(); }
if (!o.freeNav) {
bound = inRange(refCal.clone());
ref = bound || ref;
if (bound) { refCal = bound.clone(); }
}
update();
}

Expand Down Expand Up @@ -478,8 +480,8 @@ function calendar (calendarOptions) {
cell: nextMonth
});

back.disabled = !isInRangeLeft(first, true);
next.disabled = !isInRangeRight(lastDay, true);
back.disabled = !o.freeNav && !isInRange(first, true);
next.disabled = !o.freeNav && !isInRange(lastDay, true);
month.date = offsetCal.clone();

function part (data) {
Expand Down
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function defaults (options, cal) {
throw new Error('Inline calendars must be appended to a parent node explicitly.');
}
}
if (o.freeNav === no) { o.freeNav = false; } // Navigate to months outside bounds
if (o.invalidate === no) { o.invalidate = true; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so you'll need to be a little clearer on that one ace.

if (o.required === no) { o.required = false; }
if (o.date === no) { o.date = true; }
Expand Down