From 43afaeb566a9a4b7f71728941c4e1fc8a7adcc2e Mon Sep 17 00:00:00 2001 From: jelhan Date: Mon, 15 Aug 2016 12:31:11 +0200 Subject: [PATCH] add changeMonth event also updates bootstrap-datepicker to latest version not that bootstrap isn't a dependency of bootstrap-datepicker anymore https://github.com/eternicode/bootstrap-datepicker/commit/a564ef669fd7c4a5f4abadf67c0ca78b7958bc46 --- README.md | 17 +++++++++++++ addon/components/datepicker-support.js | 3 +++ bower.json | 5 ++-- .../bootstrap-datepicker-integration-test.js | 24 +++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index be03f97..fe606e2 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,23 @@ actions: { } ``` +### changeMonth + +The changeMonth action is triggered when the view month changes (e.g. user click on "prev"/"next" buttons). +Action called has new view date as first argument. + +```handlebars +{{bootstrap-datepicker changeMonth="changeMonthAction"}} +``` + +```javascript +actions: { + changeDateAction(date) { + // do sth with the new view date + } +} +``` + #### clearDate The clearDate action is triggered when the date is cleared (e.g. when the "clear" button is clicked). diff --git a/addon/components/datepicker-support.js b/addon/components/datepicker-support.js index 5538418..a0d7338 100644 --- a/addon/components/datepicker-support.js +++ b/addon/components/datepicker-support.js @@ -50,6 +50,9 @@ export default Ember.Mixin.create({ this._didChangeDate(event); }); }). + on('changeMonth', event => { + this.sendAction('changeMonth', event.date); + }). on('focusout', event => { this.sendAction('focus-out', this, event); }). diff --git a/bower.json b/bower.json index a819156..94ea9ce 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "ember-cli-bootstrap-datepicker", "dependencies": { - "ember": "1.13.7", + "ember": "1.13.13", "ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3", "ember-cli-test-loader": "ember-cli-test-loader#0.1.3", "ember-data": "1.13.8", @@ -14,6 +14,7 @@ "qunit": "~1.18.0" }, "devDependencies": { - "bootstrap-datepicker": "~1.4.0" + "bootstrap-datepicker": "~1.6.4", + "bootstrap": "~3.3.7" } } diff --git a/tests/integration/components/bootstrap-datepicker-integration-test.js b/tests/integration/components/bootstrap-datepicker-integration-test.js index d72b5c2..334496f 100644 --- a/tests/integration/components/bootstrap-datepicker-integration-test.js +++ b/tests/integration/components/bootstrap-datepicker-integration-test.js @@ -112,3 +112,27 @@ test('triggers hide action when date datepicker is hidden', function(assert) { assert.ok(actionIsTriggered, 'action is triggered'); }); + +test('triggers changeMonth when month is changed', function(assert) { + assert.expect(6); + + var lastDate; + this.on('myAction', (date) => { + assert.ok(true, 'action is triggered'); + lastDate = date; + }); + + this.render(hbs` + {{bootstrap-datepicker-inline changeMonth="myAction"}} + `); + + // there are several not visibile datepickers having .next; only trigger the visible one + this.$('.next:visible').trigger('click'); + assert.ok(lastDate instanceof Date, 'date is passed to action as argument'); + // by default view date is today; so after a click on "next" it should be a date in the next month + assert.equal(lastDate.getMonth(), new Date().getMonth() + 1, 'passed date is correct'); + + this.$('.prev:visible').trigger('click'); + assert.ok(lastDate instanceof Date, 'date is passed to action as argument'); + assert.equal(lastDate.getMonth(), new Date().getMonth(), 'passed date is correct'); +});