Skip to content

Commit 64a589b

Browse files
authored
Merge pull request soulim#82 from jelhan/changeMonth
Add changeMonth event
2 parents 6220a00 + 43afaeb commit 64a589b

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,23 @@ actions: {
224224
}
225225
```
226226

227+
### changeMonth
228+
229+
The changeMonth action is triggered when the view month changes (e.g. user click on "prev"/"next" buttons).
230+
Action called has new view date as first argument.
231+
232+
```handlebars
233+
{{bootstrap-datepicker changeMonth="changeMonthAction"}}
234+
```
235+
236+
```javascript
237+
actions: {
238+
changeDateAction(date) {
239+
// do sth with the new view date
240+
}
241+
}
242+
```
243+
227244
#### clearDate
228245

229246
The clearDate action is triggered when the date is cleared (e.g. when the "clear" button is clicked).

addon/components/datepicker-support.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export default Ember.Mixin.create({
5050
this._didChangeDate(event);
5151
});
5252
}).
53+
on('changeMonth', event => {
54+
this.sendAction('changeMonth', event.date);
55+
}).
5356
on('focusout', event => {
5457
this.sendAction('focus-out', this, event);
5558
}).

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"qunit": "~1.18.0"
1515
},
1616
"devDependencies": {
17-
"bootstrap-datepicker": "~1.4.0"
17+
"bootstrap-datepicker": "~1.6.4",
18+
"bootstrap": "~3.3.7"
1819
}
1920
}

tests/integration/components/bootstrap-datepicker-integration-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,27 @@ test('triggers hide action when date datepicker is hidden', function(assert) {
112112

113113
assert.ok(actionIsTriggered, 'action is triggered');
114114
});
115+
116+
test('triggers changeMonth when month is changed', function(assert) {
117+
assert.expect(6);
118+
119+
var lastDate;
120+
this.on('myAction', (date) => {
121+
assert.ok(true, 'action is triggered');
122+
lastDate = date;
123+
});
124+
125+
this.render(hbs`
126+
{{bootstrap-datepicker-inline changeMonth="myAction"}}
127+
`);
128+
129+
// there are several not visibile datepickers having .next; only trigger the visible one
130+
this.$('.next:visible').trigger('click');
131+
assert.ok(lastDate instanceof Date, 'date is passed to action as argument');
132+
// by default view date is today; so after a click on "next" it should be a date in the next month
133+
assert.equal(lastDate.getMonth(), new Date().getMonth() + 1, 'passed date is correct');
134+
135+
this.$('.prev:visible').trigger('click');
136+
assert.ok(lastDate instanceof Date, 'date is passed to action as argument');
137+
assert.equal(lastDate.getMonth(), new Date().getMonth(), 'passed date is correct');
138+
});

0 commit comments

Comments
 (0)