Skip to content

Commit 5fb8209

Browse files
committed
Check that selected date is within allowed bounds of min and max date
1 parent 8b9e190 commit 5fb8209

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/datetime-range.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ angular.module('g1b.datetime-range', []).
6161
}
6262
};
6363

64+
// Check if date is within bounds of min and max allowed date
65+
scope.isWithinBounds = function (date) {
66+
return ( !scope.minDate || date > scope.minDate ) && ( !scope.maxDate || date < scope.maxDate );
67+
};
68+
6469
// Update selected date
6570
scope.setDate = function (date, calendar_update) {
66-
if ( scope.selected.isSame(date) ) { return; }
71+
if ( scope.selected.isSame(date) || !scope.isWithinBounds(date) ) { return; }
6772
if ( ( scope.selected === scope.start && date < scope.end ) || ( scope.selected === scope.end && date > scope.start ) ) {
6873
scope.selected.year(date.year()).month(date.month()).date(date.date()).hours(date.hours()).minutes(date.minutes()).seconds(date.seconds());
6974
if ( (scope.selected.clone().startOf('week').month() !== scope.calendar.month() && scope.selected.clone().endOf('week').month() !== scope.calendar.month()) || calendar_update ) {

0 commit comments

Comments
 (0)