Skip to content

Commit 51f0619

Browse files
committed
Added select date functionality on the directive scope, initializing calendar date to the selected date.
1 parent 3687092 commit 51f0619

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/datetime-range.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<div class="datetime-range">
22
<div class="start-datetime"
3-
ng-click="selected = ( selected === start ) ? '' : start"
3+
ng-click="selectDate(start)"
44
ng-class="{'active': selected === start, 'warning': warning === 'start' }">
55
<div class="date">{{ start.format('DD MMMM YYYY') }}</div>
66
<div class="time">{{ start.format('HH : mm : ss') }}</div>
77
</div>
88
<div class="end-datetime"
9-
ng-click="selected = ( selected === end ) ? '' : end"
9+
ng-click="selectDate(end)"
1010
ng-class="{'active': selected === end, 'warning': warning === 'end'}">
1111
<div class="date">{{ end.format('DD MMMM YYYY') }}</div>
1212
<div class="time">{{ end.format('HH : mm : ss') }}</div>

src/datetime-range.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ angular.module('g1b.datetime-range', []).
2121
scope.current = moment();
2222

2323
// Set selected date
24+
scope.selectDate = function (date) {
25+
if ( scope.selected === date ) {
26+
scope.selected = undefined;
27+
} else {
28+
scope.selected = date;
29+
scope.calendar = scope.selected.clone();
30+
}
31+
};
32+
33+
// Update selected date
2434
scope.setDate = function (date) {
2535
if ( scope.selected.isSame(date) ) { return; }
2636
if ( ( scope.selected === scope.start && date < scope.end ) || ( scope.selected === scope.end && date > scope.start ) ) {

0 commit comments

Comments
 (0)