ui-select2
ui-select2 copied to clipboard
Setting priority 1 on select2.js directive introduces a rendering problem on selecting from the dropdown
I am working with sanathko on a project that uses select2 and this is related to bug https://github.com/angular-ui/ui-select2/issues/110 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 set mine to a higher priority and was able to get around this (also using 1.2rc3)
When you say 'higher priority', can you be more specific. I tried setting it to 100 but it didn't work. I don't want to have to try every number between 1 and and 100 - it might take a while. Cheers.
I set mine to 1000 (a little obscene I know)... I think I read that the issue was do to an the angular
Before I had increased the priority, I had used a work around where I set a $timeout and delayed binding for 50ms
Ah $timeout - that fixes quite a lot of things! I increased the priority to 2 and it so far seems to work.
So ... How is going the fix?
We upgraded to the latest Angular. Which is actually better in the long run. This broke other things but it was a necessary thing to do. In the long run it's best to be using the latest version of things.
Sent from my iPhone
On 25 Feb 2014, at 5:20 am, Thiago Cardoso de Castro [email protected] wrote:
So ... How is going the fix?
— Reply to this email directly or view it on GitHub.
We are still having issues with this. Using latest Angular buiild and latest select2 directive. It's very random. Most of the time it works as fine as expected and then it will suddenly stop performing and not select the pre - selected choice
i have this very problem when i use array data with ng-options
.
for example
// controller
$scope.genders = ['male', 'female'];
// view
<select ng-options="gender as gender for gender in genders"></select>
i solved the problem by make genders
an array of objects instead.
// controller
$scope.genders = [
{ label: 'male', value: 'm' },
{ label: 'female', value: 'f' }
];
// view
<select ng-options="gender.value as gender.label for gender in genders"></select>
the problem was gone. i don't know what angular or ui-select2 handle this behind the scene though.
Same problem as armno, but changing to an array of objects did not help. "angular": "1.2.15", "angular-ui-select2": "~0.0.5", "select2": "~3.5.0" also tried with (which bower install says angular-ui-select2 requires): "select2": "~3.4.8"
I also tried setting the priority in the directive to 1000, but no luck.
Any other ideas?
My problem was that I was using ng-options, which the docs say is not supported. Using inline options or a repeat on options worked as expected.
I had this problem as well https://github.com/angular-ui/ui-select2/issues/110 as @DomClaxton mentioned above, and spent a couple of days investigating this!
I needed to use the unsupported ng-options directive like @rkoberg mentioned because I want the model to update as an array of objects, not as an array of strings which is a limitation in my opinion. This stack overflow explains why I need to do that.
HOWEVER:
I noticed that when I use ui select2 from 'angular-ui' here (granted it's an old repo) I no longer had the bug. When I used select2 from this repository it did NOT work.
Open closely examining the differences between the two directives I noticed that angular-ui-select2 had priority: 1 and angular-ui did not have any priority.
So I simply removed priority: 1 (without upping the number) and it worked for me.
Is there any reason why this priority needs to be there? It wasn't there in the older repository so why do we need it now?