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

Setting priority 1 on select2.js directive introduces a rendering problem on selecting from the dropdown #111

Open
DomClaxton opened this issue Nov 27, 2013 · 11 comments
Labels

Comments

@DomClaxton
Copy link

I am working with sanathko on a project that uses select2 and this is related to bug #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.

@chriswjones
Copy link

I set mine to a higher priority and was able to get around this (also using 1.2rc3)

@DomClaxton
Copy link
Author

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.

@chriswjones
Copy link

I set mine to 1000 (a little obscene I know)... I think I read that the issue was do to an the angular or some other control taking over the default binding, and setting the priority can help override that. To be honest I have not had time to research it, and with it currently working for me it is a low priority (although something I am not very confident in). Before I had increased the priority, I had used a work around where I set a $timeout and delayed binding for 50ms

@DomClaxton
Copy link
Author

Ah $timeout - that fixes quite a lot of things! I increased the priority to 2 and it so far seems to work.

@ThCC
Copy link

ThCC commented Feb 24, 2014

So ... How is going the fix?

@DomClaxton
Copy link
Author

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.

@DomClaxton
Copy link
Author

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

@armno
Copy link

armno commented May 26, 2014

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.

@rkoberg
Copy link

rkoberg commented Jul 22, 2014

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?

@rkoberg
Copy link

rkoberg commented Jul 23, 2014

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.

@stevebrowndotco
Copy link

I had this problem as well #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?

stevebrowndotco added a commit to stevebrowndotco/ui-select2 that referenced this issue Jul 30, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants