ember-cli-bootstrap-datepicker
Advanced tools
@@ -9,3 +9,4 @@ import Ember from 'ember'; | ||
| element = this.$(), | ||
| value = this.get('value'); | ||
| value = this.get('value'), | ||
| dates = []; | ||
@@ -24,2 +25,4 @@ element. | ||
| minViewMode: this.get('minViewMode'), | ||
| multidate: this.get('multidate'), | ||
| multidateSeparator: this.get('multidateSeparator'), | ||
| orientation: this.get('orientation'), | ||
@@ -39,3 +42,17 @@ startDate: this.get('startDate'), | ||
| if (value) { | ||
| element.datepicker('update', new Date(value)); | ||
| if (this.get('multidate')) { | ||
| // split datesIsoString by multidate separator | ||
| var multidateSeparator = this.get('multidateSeparator') || ','; | ||
| var isoDates = value.split(multidateSeparator); | ||
| // generate array of date objecs | ||
| dates = isoDates.map(function(date) { | ||
| return self._resetTime(new Date(date)); | ||
| }); | ||
| } | ||
| else { | ||
| dates = [self._resetTime(new Date(value))]; | ||
| } | ||
| element.datepicker. | ||
| apply(element, Array.prototype.concat.call(['update'], dates)); | ||
| } | ||
@@ -52,7 +69,44 @@ }.on('didInsertElement'), | ||
| if (event.date) { | ||
| isoDate = this.$().datepicker('getUTCDate').toISOString(); | ||
| if (this.get('multidate')) { | ||
| // set value to array if multidate | ||
| isoDate = this.$().datepicker('getUTCDates').map(function(date) { | ||
| return date.toISOString(); | ||
| }); | ||
| } | ||
| else { | ||
| isoDate = this.$().datepicker('getUTCDate').toISOString(); | ||
| } | ||
| } | ||
| this.set('value', isoDate); | ||
| }, | ||
| didChangeValue: function() { | ||
| var self = this, | ||
| element = this.$(), | ||
| value = this.get('value'), | ||
| dates = []; | ||
| if (Ember.isArray(value)) { | ||
| dates = value.map(function(date) { | ||
| return self._resetTime(new Date(date)); | ||
| }); | ||
| } else { | ||
| dates = [self._resetTime(new Date(value))]; | ||
| } | ||
| element.datepicker. | ||
| apply(element, Array.prototype.concat.call(['update'], dates)); | ||
| }.observes('value'), | ||
| // HACK: Have to reset time to 00:00:00 because of the bug in | ||
| // bootstrap-datepicker | ||
| // Issue: http://git.io/qH7Hlg | ||
| _resetTime: function(date) { | ||
| date.setHours(0); | ||
| date.setMinutes(0); | ||
| date.setSeconds(0); | ||
| return date; | ||
| } | ||
| }); |
+1
-1
| { | ||
| "name": "ember-cli-bootstrap-datepicker", | ||
| "version": "0.3.0", | ||
| "version": "0.3.1", | ||
| "description": "Datepicker component for Ember CLI based on bootstrap-datepicker", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -251,2 +251,42 @@ <div class="container"> | ||
| <h3>multidate</h3> | ||
| <div class="panel panel-default"> | ||
| <div class="panel-heading"> | ||
| <pre><code>{{bootstrap-datepicker multidate=true placeholder="Click to play" class="form-control"}}</code></pre> | ||
| </div> | ||
| <div class="panel-body"> | ||
| <p> | ||
| Type: <code>Boolean</code> or <code>Number</code><br> | ||
| Default: <code>false</code></code> | ||
| </p> | ||
| <p>If multidate is <code>true</code>, <code>value</code> is an array.</p> | ||
| <p>Please, read more about possible values <a href="http://bootstrap-datepicker.readthedocs.org/en/release/options.html#multidate">here</a>.</p> | ||
| </div> | ||
| <div class="panel-footer"> | ||
| {{bootstrap-datepicker multidate=true | ||
| placeholder="Click to play" | ||
| class="form-control"}} | ||
| </div> | ||
| </div> | ||
| <h3>multidateSeparator</h3> | ||
| <div class="panel panel-default"> | ||
| <div class="panel-heading"> | ||
| <pre><code>{{bootstrap-datepicker multidate=true multidateSeparator=";" placeholder="Click to play" class="form-control"}}</code></pre> | ||
| </div> | ||
| <div class="panel-body"> | ||
| <p> | ||
| Type: <code>String</code><br> | ||
| Default: <code>,</code></code> | ||
| </p> | ||
| <p>Please, read more about possible values <a href="https://bootstrap-datepicker.readthedocs.org/en/release/options.html#multidateseparator">here</a>.</p> | ||
| </div> | ||
| <div class="panel-footer"> | ||
| {{bootstrap-datepicker multidate=true | ||
| multidateSeparator=";" | ||
| placeholder="Click to play" | ||
| class="form-control"}} | ||
| </div> | ||
| </div> | ||
| <h3>orientation</h3> | ||
@@ -253,0 +293,0 @@ <div class="panel panel-default"> |
@@ -43,1 +43,26 @@ import { test, moduleForComponent } from 'ember-qunit'; | ||
| }); | ||
| test('should set dates provided by value (multidate, default multidateSeparator)', function(){ | ||
| expect(2); | ||
| var component = this.subject({ | ||
| value: '2015-01-13T00:00:00.000Z,2015-01-07T00:00:00.000Z,2015-01-15T00:00:00.000Z', | ||
| multidate: true | ||
| }); | ||
| equal(this.$().val(), '01/13/2015,01/07/2015,01/15/2015', 'should set value as input field value'); | ||
| equal(this.$().datepicker('getDates').length, 3, 'should set internal datepicker dates by value'); | ||
| }); | ||
| test('should set dates provided by value (multidate, multidateSeparator provided)', function(){ | ||
| expect(2); | ||
| var component = this.subject({ | ||
| value: '2015-01-13T00:00:00.000Z;2015-01-07T00:00:00.000Z;2015-01-15T00:00:00.000Z', | ||
| multidate: true, | ||
| multidateSeparator: ';' | ||
| }); | ||
| equal(this.$().val(), '01/13/2015;01/07/2015;01/15/2015', 'should set value as input field value using multidate separator'); | ||
| equal(this.$().datepicker('getDates').length, 3, 'should set internal datepicker dates by value'); | ||
| }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
42558
11.06%444
17.77%0
-100%