From 9a115bd48baf6cf24a2ef666f1d3e3a6a3111c29 Mon Sep 17 00:00:00 2001 From: lazybensch Date: Mon, 14 Sep 2015 17:05:27 +0200 Subject: [PATCH 1/2] add customParser support --- addon/components/datepicker-support.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addon/components/datepicker-support.js b/addon/components/datepicker-support.js index 5b868bd..5538418 100644 --- a/addon/components/datepicker-support.js +++ b/addon/components/datepicker-support.js @@ -9,6 +9,9 @@ export default Ember.Mixin.create({ language: undefined, startDate: undefined, endDate: undefined, + customParser: function(value) { + return value; + }, setupBootstrapDatepicker: Ember.on('didInsertElement', function() { @@ -134,6 +137,7 @@ export default Ember.Mixin.create({ _updateDatepicker: function() { var element = this.$(), value = this.get('value'), + customParser = this.get('customParser'), dates = []; if (!this.get('mustUpdateInput')) { @@ -141,6 +145,8 @@ export default Ember.Mixin.create({ return; } + value = customParser(value); + switch (Ember.typeOf(value)) { case 'array': dates = value; From 67b7738c4b2e935f350daed911c65a36a3cfa181 Mon Sep 17 00:00:00 2001 From: lazybensch Date: Mon, 14 Sep 2015 17:15:03 +0200 Subject: [PATCH 2/2] add test for customParser --- .../components/bootstrap-datepicker-test.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/unit/components/bootstrap-datepicker-test.js b/tests/unit/components/bootstrap-datepicker-test.js index dcae6ac..8c27b3f 100644 --- a/tests/unit/components/bootstrap-datepicker-test.js +++ b/tests/unit/components/bootstrap-datepicker-test.js @@ -42,6 +42,32 @@ test('displays date with custom format when format is set', function(assert) { assert.equal(this.$().val(), '31.Dec.14'); }); +test('resets date when input is cleared', function(assert) { + this.subject({ + value: new Date(2014, 11, 31) + }); + + assert.ok(this.$().datepicker('getDate'), 'initial value is set'); + + this.$().val(''); + this.$().trigger('input'); + + assert.equal(this.$().datepicker('getDate'), null, 'value is reset when input is cleared'); +}); + +test('should use customParser if provided', function(assert) { + assert.expect(1); + + this.subject({ + value: '2015-09-14T16:59:01+02:00', + customParser: function(value) { + return new Date(value); + } + }); + + assert.equal(this.$().val(), '09/14/2015'); +}); + test('sets dates provided by value (multidate, default multidateSeparator)', function(assert) { this.subject({ value: [new Date(2015, 0, 13), new Date(2015, 0, 7), new Date(2015, 0, 15)],