You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 8, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 8, 2020. It is now read-only.
What I expect is, if we feed a collection as options and and the initial selection (akin to selectedin normal select box) should be set to the current ng-model. I am not sure the initSelection is the right was as indicated in the SO post.
Any updates on this? I'm doing what I thought was a simple ng-model = array of selected items to initialize the select2 element, and at some point it recognizes them because the selected items are omitted from the options, but they don't show up as tags.
@fghibellini
i can't find this option in select2 docs, where did you get that info?
I've tried to set this setting but it doesn't change anything :-(.
I've bound an array with ngOptions like 'item.id as item.name for item in items' and set the ngModel to the itemId which should be selected by default...
@fghibellini simple_tags is as the name says only for tags-feature, which only gets in place when isSelect = false so the convertToAngularModel and convertToSelect2Model Functions getting called.
This will not fix my problem :-(.
bsr2 was having this issue with a ajax/multiple option set, so this differes from the original question by the-spike i think.
So the solution by Sharondi is also not solving my problem becaue initSelection is not called on singleselect.
On line 95 elm.select2('val', controller.$viewValue); is getting called which is (in my case) undefined -> which results in the output you can see in my post before. But I don't know why this is happening...
Edit:
Sorry line 95 is not getting called...
Edit2:
Okay I should read the readme carefully...:
Working with dynamic options
ui-select2 is incompatible with select ng-options. For the best results use option ng-repeat instead.
Sorry for wasting your time!
I have done a pull request which fixes this issue. ng-model binds to the id returned by select2 and it also allows you to bind a property in your controller to the select2 data object using a ui-data attribute.
Activity
BaconSoap commentedon Dec 19, 2013
Hi, just to clarify: you're asking if when binding select2 to an array of objects, if you can make ng-model be the selected object's id?
the-spyke commentedon Dec 19, 2013
Hi, yes.
bsr203 commentedon Dec 20, 2013
Hi I have same/similar question. same as http://stackoverflow.com/questions/14985346/setting-initial-values-of-angular-ui-select2-multiple-directive
What I expect is, if we feed a collection as options and and the initial selection (akin to
selectedin normal select box) should be set to the currentng-model. I am not sure theinitSelectionis the right was as indicated in the SO post.Sharondio commentedon Jan 3, 2014
Any updates on this? I'm doing what I thought was a simple ng-model = array of selected items to initialize the select2 element, and at some point it recognizes them because the selected items are omitted from the options, but they don't show up as tags.
Sharondio commentedon Jan 4, 2014
OK, got it working with the initSelection:
initSelection : function (element, callback) {
callback($(element).data('$ngModelController').$modelValue);
},
But I'm with bsr203, feels a bit hacky.
fghibellini commentedon Feb 21, 2014
there is a simple_tags option that when set to true assigns the object's id instead of the object itself to the model
sroe commentedon Feb 27, 2014
@fghibellini

i can't find this option in select2 docs, where did you get that info?
I've tried to set this setting but it doesn't change anything :-(.
I've bound an array with ngOptions like 'item.id as item.name for item in items' and set the ngModel to the itemId which should be selected by default...
fghibellini commentedon Feb 27, 2014
https://github.com/angular-ui/ui-select2/blob/master/src/select2.js
lines 42 & 62
fghibellini commentedon Feb 27, 2014
but it seems to work only when you have a multiple choice input
see #159
sroe commentedon Feb 27, 2014
@fghibellini simple_tags is as the name says only for tags-feature, which only gets in place when isSelect = false so the convertToAngularModel and convertToSelect2Model Functions getting called.
This will not fix my problem :-(.
bsr2 was having this issue with a ajax/multiple option set, so this differes from the original question by the-spike i think.
So the solution by Sharondi is also not solving my problem becaue initSelection is not called on singleselect.
On line 95 elm.select2('val', controller.$viewValue); is getting called which is (in my case) undefined -> which results in the output you can see in my post before. But I don't know why this is happening...
Edit:
Sorry line 95 is not getting called...
Edit2:
Okay I should read the readme carefully...:
Working with dynamic options
ui-select2 is incompatible with select ng-options. For the best results use option ng-repeat instead.
Sorry for wasting your time!
dfsq commentedon Jun 1, 2014
Any update on that?
shawn-simon commentedon Sep 11, 2014
This is really a huge pain in the ass haha
RedJandal commentedon Sep 15, 2014
I have done a pull request which fixes this issue. ng-model binds to the id returned by select2 and it also allows you to bind a property in your controller to the select2 data object using a ui-data attribute.
Check it out and let me know what you think:
#276
snimavat commentedon Dec 30, 2014
Any updates? we load select2 with ajax array of objects, but want objects id to be bound to model
PowerKiKi commentedon Dec 30, 2014
This project is deprecated. Fixes and new features are very unlikel yto happen. You should instead consider a migration to ui-select.