Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When passing objects as content/selection removing them throws error #44

Closed
LevelbossMike opened this issue Mar 18, 2015 · 9 comments
Closed

Comments

@LevelbossMike
Copy link

Hi!

When passing an array of Objects to the content property (e.g. an array of ember-data models) and using content as optionsValuePath (e.g. as needed by ember-data when working with relationships) removing an object from the selection throws an error in selectize.

Uncaught TypeError: $item.attr is not a function in selectize's removeItem-method

Because the observers that trigger this code are also triggered on willDestroyElement this also fails when removing the component from the DOM.

This makes this addon basically unusable for working with ember-data relationships which is very unfortunate because ember.select is also not working for ember-data relationships ;).

I am happy to help with solving this issue but I think input from @miguelcobain would be very useful as I am not really familiar with selectize or ember-cli-selectize.

Any idea what's the problem here?

And of course thanks for this great addon!

@miguelcobain
Copy link
Owner

The correct property name is optionValuePath and not optionsValuePath, as stated in the readme.
Please confirm if this was the problem. If the problem persists, please post the template you used.

Ember data objects should definitely work.

@LevelbossMike
Copy link
Author

Sorry that was a typo. I am using optionValuePath and it's really not working :(.

Template:

{{ember-selectize content=tags selection=picture.tags optionLabelPath='content.name' optionValuePath='content' multiple=true}}

This does not work if tags is a hasMany relationship and also it does not work when tags is an array of Ember.Objects.

@miguelcobain
Copy link
Owner

What's does the template you're using to render ember-selectize looks like?

@LevelbossMike
Copy link
Author

just updated.

@miguelcobain
Copy link
Owner

The problem is probably related with optionValuePath='content'.

Selectize requires us to have unique identifiers for each of our options. What were you really trying to accomplish with optionValuePath='content'?

A typical use would be optionValuePath='content.id'.

@LevelbossMike
Copy link
Author

I want to pass the Ember data model. That's required when working with
relationships as Ember data will take care of serialzing this into the
correct JSON representation.
Am 18.03.2015 16:07 schrieb "Miguel Andrade" notifications@github.com:

The problem is probably related with optionValuePath='content'.

Selectize requires us to have unique identifiers for each of our options.
What were you really trying to accomplish with optionValuePath='content'?


Reply to this email directly or view it on GitHub
#44 (comment)
.

@miguelcobain
Copy link
Owner

The Ember data models are already being passed through content=tags.
Also, since multiple=true, then selection will be an array filled with objects from tags. Since selection is bound to picture.tags, then picture.tags will have ember data models.

Isn't this what your aiming at?

@LevelbossMike
Copy link
Author

Aaah! Thanks a lot. valueOptionPath 'content.id' works correctly. 👍 Thanks for helping out!

@LevelbossMike
Copy link
Author

Oh and I also noticed that I am apparently too dumb to read the documentation correctly because it's basically in the documentation how to do this. Sorry for bothering and thanks for your help again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants