ember-cli-selectize
ember-cli-selectize copied to clipboard
[BUG] At ember 2.0.x. Selection = PromiseManyArray, asserted not an array
At Ember 2.0.x, Ember-data 2.0.x:
I'm using selection=model.tags
, where model's tag is defined like tags: DS.hasMany('tags', { async: true})
which asserts:
Uncaught Error: Assertion Failed: When ember-selectize is in multiple mode, the provided selection must be an array.
In the code, the assert uses isArray
in order to check if property selection
is an array, but @wecc pointed at Slack that Ember.isArray
is the same as Array.isArray
and it doesn't check for array-like
, which in this case would result on false
. Is there another way to check this assert?
Another thing I noticed, is that it should be using something like this.setAttr('selection', selection)
instead of current this.set('selection', selection)
at addon/components/ember-selectize.js:L360 and addon/components/ember-selectize.js:L473
Thanks for the awesome job :)
Hi @marcemira, did you find a work around this issue?
@GabKlein not yet... :/ but @miguelcobain told me that he'll take a look
I'm also having issues with a newly created model. A category belongsTo relationship which is empty is used on selection = model.category. This throws Cannot call get with 'id' on an undefined object
Does anyone have a clue? I'll have to get my hands dirty on this addon or replace it. I'll do the first...
My workaround is to add a property in the controller that return an has_many array.
clients: function() {
return this.get('model.clients').reject(function(object) {
return object.get('hasDirtyAttributes');
});
}.property('model.clients')
Note the reject, this avoid to get new objects before they get saved. eg:
this.store.createRecord('order', {
reference: reference,
organization: this.model
}));
Yeah, getting this too. Will try @GabKlein's solution, and report back.
Ok, so @GabKlein's solution was not helpful in my case. I had to manually update ember-selectize.js
in 3 places.
It turns out that all we need to do is use this.get("selection").toArray()
to convert the promisy object to an array-like object.
For example, line 328:
if (multiple && isArray(selection.toArray()) && obj) {
selection = selection.toArray();
if (!selection.findBy(this.get('_valuePath'), get(obj, this.get('_valuePath')))) {
this._addSelection(obj);
}
Then in the corresponding spots in _onItemRemove(value)
and _onItemAdd(value)
.
Same issue here.
Try to call toArray()
before passing the array to selectize.
+1
My fork solves that: https://github.com/tobsch/ember-cli-selectize I don't like the idea of just converting toArray though.