-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
selectionBinding in Ember.Select don't work together with associations #82
Comments
The problem is that Em.Select sets the whole object not just the id. Try selecting an item in your 3rd select and see the value of EmberApp.MyView.get('testId'). It's going to output an object (the model object). Currently, Em.Select doesn't support selection by value. It shouldn't be hard to implement it, something like: value: Em.Computed(function(key, value){
var content = get(this, 'content'),
select = null,
self = this;
if (value !== undefined){ //set
content.forEach(function(item, idx){
if (item.get(self.get('optionValuePath')) == value)
{
select = item;
return;
}
});
this.get('selection').pushObject(select);
return value;
}
return this.get('selection').get(self.get('optionValuePath'));
}).property('selection').cacheable() I did not test it. Maybe I'll give it a shoot later and if I got lucky I'm going to create a pull request for it. |
Here it is: http://jsfiddle.net/YJ7zM/6/ It will only work for "id" as optionValuePath, but it illustrates the idea. Hope that helps. |
It would be very cool to have your jsfiddle integrated. Could you write tests and send a PR ? |
If @ebryn says that's the way to go, I'll do it. Maybe he has a better idea. |
The above solution didn't fully work for me. I had to set the contextBinding as well. I also made it so I could bind to any value, but I have a feeling the current code might fail in some situations.
|
The original jsFiddle referenced (http://jsfiddle.net/sandstrom/YJ7zM/3/) only has one valid usage of @sandstrom The issue is you're trying to use the fixture data directly in the There doesn't seem to actually be a bug here so I'm closing this issue. |
I used the fixture data only to setup a simple test case (maybe I shouldn't have done that). Anyway, just close the issue if it isn't a bug. Thanks for taking time looking at it! |
There seem to be a problem with associations and Ember.Select (built-in view). My guess is that the objects are compared with === and the comparison returns false, since they are different instances. I've tried to track down the lines in the source where this happens, but haven't found it.
Handlebars code:
This is the javascript:
http://jsfiddle.net/sandstrom/YJ7zM/3/
The text was updated successfully, but these errors were encountered: