Skip to content
This repository was archived by the owner on Dec 26, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions addon/components/datepicker-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -134,13 +137,16 @@ export default Ember.Mixin.create({
_updateDatepicker: function() {
var element = this.$(),
value = this.get('value'),
customParser = this.get('customParser'),
dates = [];

if (!this.get('mustUpdateInput')) {
this.set('mustUpdateInput', true);
return;
}

value = customParser(value);

switch (Ember.typeOf(value)) {
case 'array':
dates = value;
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/components/bootstrap-datepicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this test for? It looks like testing bootstrap-datepicker behavior but not this addon. Shouldn't the expected value be this.get('value')?

});

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)],
Expand Down