Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

select2 dropdown selected value doesn't get updated with the updated model #110

Closed
sanathko opened this issue Nov 22, 2013 · 5 comments
Closed

Comments

@sanathko
Copy link

I use the latest select2 api (select2-3.4.5) and my html for select 2 looks like this.

         <select ui-select2 id="select2-test" ng-model="mymodel.myTitle">
            <option value="">Title</option>
            <option ng-repeat="title in nameList" value="{{title.key}}">{{title.name}}</option>
        </select>

I am performing a save call in my controller which saves the model and reloads the saved model back. This is done inside the following block.

         $timeout(function(){
            //if(!$scope.$$phase){
                $scope.$apply(function(){
                    //update the model
                    //update code
                })
            //};
        }, 50);

all my text fields gets loaded with the updated data and when I printout {{mymodel}}, I can see the updated model.
I performed save and update call inside $scope.$apply with the intention of updating the dom elements.

after the update when I expand the dropdown (select2), I can see the correctly updated value selected inside the select options.

       <option XXXX selected="selected">MYSELECTED</option>

but select2-container which has

        <span class="select2-chosen">OLD</span> has the old value hence it is shown as the selected value.

Is this an issue with select 2 or am I missing anything?

@ProLoser
Copy link
Member

My guess is you're using angular 1.2

@DomClaxton
Copy link

I am working with sanathko on a project that uses select2. The fix here does address the problem we were having but now it has introduced a new problem.

The new problem is as follows:
When a user selects from the select2 dropdown the model gets updated and the 'selection' is made but... it is not displayed on the first attempt. If the user chooses the same dropdown choice then it is displayed correctly.
We are using Angular1.2.rc3 and not the latest version of Angular.
I will create a new ticket for this

@babupasungily
Copy link

@DomClaxton Hi DomClaxton,

I too have the same issue with slect2 js with Angular. Did you find any fix for this?

@DeepzSandra
Copy link

I too have the same issue with slect2 js with Angular. Anybody please tell me..

@romerromero
Copy link

Me pasa lo mismo con el angularjs y el select2

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

No branches or pull requests

6 participants