-
Notifications
You must be signed in to change notification settings - Fork 52
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
Object values instead of simple values #15
Comments
Should work, but an $scope.foo = null;
$scope.bar = null; |
I'm sorry, I don't understand what you mean. In my plunker you can see that with regular selectboxes I can use objects where with select2 it doesn't work. Whatever I choose from the list, the model is always set to the last entry in the list. |
Check the video I linked. Anyway, that's not an angular-select2 issue, but you will be in trouble if you don't learn it. As for objects: values in the select2 widget are keyed by their toString value, so if your objects define unique toString values, it should work. If not, I suggest you don't use objects as values (it's ugly anyway), use an index key. |
Hey rubenv Thank you for that awesome select2-wrapper! I am running into the same problem as TheYves though. AngularJS can assign whole objects to a variable in a select (which you say is ugly, can you elaborate on that?), but the directive assigns the object's toString-method as array key, which leads to the last item in the array being selected, no matter which element was clicked on in the dropdown. Might I suggest a solution where the directive checks wether or not the value is a String or an object, and if it's an object check for an id (or even better, look for the "track by"-attribute of the query string)? If you are open to the suggestion I can even write the functionality and make a pull request. Regards |
Sure, track by makes total sense! |
@DonHaron have you already implemented your suggestion? I would be very interested. :) |
@TheYves I started it and made it work, but it was rubbish and not in line with the ngSelect directive, and broke other parts of the select2-directive. So I will have to do a proper rewrite based on ngSelect. I didn't get to it yet though... |
Okay, thanks for the reply. |
Any update on this issue? |
Is it possible to have objects as values instead simple values?
Here's a plunker: http://plnkr.co/edit/GgfVAn8M4DvAIWzLyI5b?p=preview
The text was updated successfully, but these errors were encountered: