Skip to content
This repository was archived by the owner on Dec 26, 2019. It is now read-only.

Commit 31a585d

Browse files
committed
fix: handling of value for multidate
added tests
1 parent 695d727 commit 31a585d

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

addon/components/datepicker-support.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,22 @@ export default Ember.Mixin.create({
3636
});
3737

3838
if (value) {
39-
element.datepicker('update', new Date(value));
39+
if (this.get('multidate')) {
40+
// split datesIsoString by multidate separator
41+
var multidateSeparator = this.get('multidateSeparator') || ',';
42+
var dateIsoStrings = value.split( multidateSeparator );
43+
// generate array of date objecs
44+
var dateObjects = dateIsoStrings.map( function(dateIsoString) {
45+
return new Date(dateIsoString);
46+
});
47+
// set datepickers internal date
48+
element.datepicker('setDates', dateObjects);
49+
// update datepicker view
50+
element.datepicker('update');
51+
}
52+
else {
53+
element.datepicker('update', new Date(value));
54+
}
4055
}
4156
}.on('didInsertElement'),
4257

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,28 @@ test('should display date with custom format when format is set', function(){
4040

4141
equal(this.$().val(), '31.Dec.14');
4242
});
43+
44+
test('should set dates provided by value (multidate, default multidateSeparator)', function(){
45+
expect(2);
46+
47+
var component = this.subject({
48+
value: '2015-01-13T00:00:00.000Z,2015-01-07T00:00:00.000Z,2015-01-15T00:00:00.000Z',
49+
multidate: true
50+
});
51+
52+
equal(this.$().val(), '01/13/2015,01/07/2015,01/15/2015', 'should set value as input field value');
53+
equal(this.$().datepicker('getDates').length, 3, 'should set internal datepicker dates by value');
54+
});
55+
56+
test('should set dates provided by value (multidate, multidateSeparator provided)', function(){
57+
expect(2);
58+
59+
var component = this.subject({
60+
value: '2015-01-13T00:00:00.000Z;2015-01-07T00:00:00.000Z;2015-01-15T00:00:00.000Z',
61+
multidate: true,
62+
multidateSeparator: ';'
63+
});
64+
65+
equal(this.$().val(), '01/13/2015;01/07/2015;01/15/2015', 'should set value as input field value using multidate separator');
66+
equal(this.$().datepicker('getDates').length, 3, 'should set internal datepicker dates by value');
67+
});

0 commit comments

Comments
 (0)