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

Commit cd8ef76

Browse files
committed
Merge pull request #68 from HerveSeger/develop
Fix issue #59
2 parents 4d21b36 + 8195bd6 commit cd8ef76

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

addon/components/datepicker-support.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default Ember.Mixin.create({
2525
enableOnReadonly: this.get('enableOnReadonly'),
2626
endDate: this.get('endDate'),
2727
forceParse: this.get('forceParse'),
28-
format: this.get('format'),
28+
format: this._toString(this.get('format')),
2929
immediateUpdates: this.get('immediateUpdates'),
3030
keyboardNavigation: this.get('keyboardNavigation'),
3131
language: this.get('language') || undefined,
@@ -113,8 +113,9 @@ export default Ember.Mixin.create({
113113
});
114114

115115
this.addObserver('format', function() {
116-
this.$().datepicker('format', this.get('format'));
117-
this.$().data('datepicker')._process_options({format: this.get('format')});
116+
let format = this._toString(this.get('format'));
117+
this.$().datepicker('format', format);
118+
this.$().data('datepicker')._process_options({format: format});
118119
this._updateDatepicker();
119120
});
120121
}),
@@ -160,5 +161,23 @@ export default Ember.Mixin.create({
160161
clone.setMilliseconds(0);
161162

162163
return clone;
164+
},
165+
166+
/**
167+
* Fix Issue #59
168+
* _toString Checks and converts the input object and returns a String if it is required and feasible
169+
* @param {Object} obj The object to check
170+
* @return {Object} The object as a String
171+
*/
172+
_toString: function (obj) {
173+
if (typeof obj !== typeof Undefined && obj !== typeof String) {
174+
if (typeof obj.toString === typeof Function) {
175+
obj = obj.toString();
176+
} else {
177+
// No toString() method available - There is nothing else that can be done
178+
throw new Error("At _toString() (datepicker-support.js) - No toString() method available for the passed object.");
179+
}
180+
}
181+
return obj;
163182
}
164183
});

0 commit comments

Comments
 (0)