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

Commit 212b47c

Browse files
committed
Add support for more options
* multidate * multidateSeparator Thanks @jelhan.
2 parents c8bfc38 + 31a585d commit 212b47c

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

addon/components/datepicker-support.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default Ember.Mixin.create({
2020
keyboardNavigation: this.get('keyboardNavigation'),
2121
language: this.get('language'),
2222
minViewMode: this.get('minViewMode'),
23+
multidate: this.get('multidate'),
24+
multidateSeparator: this.get('multidateSeparator'),
2325
orientation: this.get('orientation'),
2426
startDate: this.get('startDate'),
2527
startView: this.get('startView'),
@@ -34,7 +36,22 @@ export default Ember.Mixin.create({
3436
});
3537

3638
if (value) {
37-
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+
}
3855
}
3956
}.on('didInsertElement'),
4057

@@ -46,7 +63,15 @@ export default Ember.Mixin.create({
4663
var isoDate = null;
4764

4865
if (event.date) {
49-
isoDate = this.$().datepicker('getUTCDate').toISOString();
66+
if (this.get('multidate')) {
67+
// set value to array if multidate
68+
isoDate = this.$().datepicker('getUTCDates').map(function(date) {
69+
return date.toISOString();
70+
});
71+
}
72+
else {
73+
isoDate = this.$().datepicker('getUTCDate').toISOString();
74+
}
5075
}
5176

5277
this.set('value', isoDate);

tests/dummy/app/templates/index.hbs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,46 @@ ember generate bootstrap-datepicker</pre>
248248
</div>
249249
</div>
250250

251+
<h3>multidate</h3>
252+
<div class="panel panel-default">
253+
<div class="panel-heading">
254+
<pre><code>&#123;&#123;bootstrap-datepicker multidate=true placeholder="Click to play" class="form-control"&#125;&#125;</code></pre>
255+
</div>
256+
<div class="panel-body">
257+
<p>
258+
Type: <code>Boolean</code> or <code>Number</code><br>
259+
Default: <code>false</code></code>
260+
</p>
261+
<p>If multidate is <code>true</code>, <code>value</code> is an array.</p>
262+
<p>Please, read more about possible values <a href="http://bootstrap-datepicker.readthedocs.org/en/release/options.html#multidate">here</a>.</p>
263+
</div>
264+
<div class="panel-footer">
265+
{{bootstrap-datepicker multidate=true
266+
placeholder="Click to play"
267+
class="form-control"}}
268+
</div>
269+
</div>
270+
271+
<h3>multidateSeparator</h3>
272+
<div class="panel panel-default">
273+
<div class="panel-heading">
274+
<pre><code>&#123;&#123;bootstrap-datepicker multidate=true multidateSeparator=";" placeholder="Click to play" class="form-control"&#125;&#125;</code></pre>
275+
</div>
276+
<div class="panel-body">
277+
<p>
278+
Type: <code>String</code><br>
279+
Default: <code>,</code></code>
280+
</p>
281+
<p>Please, read more about possible values <a href="https://bootstrap-datepicker.readthedocs.org/en/release/options.html#multidateseparator">here</a>.</p>
282+
</div>
283+
<div class="panel-footer">
284+
{{bootstrap-datepicker multidate=true
285+
multidateSeparator=";"
286+
placeholder="Click to play"
287+
class="form-control"}}
288+
</div>
289+
</div>
290+
251291
<h3>orientation</h3>
252292
<div class="panel panel-default">
253293
<div class="panel-heading">

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)