ember-cli-bootstrap-datepicker
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -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; | ||
} | ||
}); |
{ | ||
"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": { |
@@ -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'); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
444
0