Skip to content
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

ajax.templateSelection() is called twice for every selection event #3616

Closed
renehamburger opened this issue Jul 27, 2015 · 17 comments
Closed

Comments

@renehamburger
Copy link

This can be reproduced with the ajax example given at https://select2.github.io/examples.html and a breakpoint in formatRepoSelection().

@francescomeloni
Copy link

someone can suggest a workaround for this bug?

@smoothlikejazz
Copy link

Love this Library, I also ran into this; So in revisiting and looking through the code there is an event called "selection:update"; the listener is registered twice,
Once in SingleSelection.prototype.bind and again in BaseSelection.prototype.bind

container.on('selection:update', function (params) {
      self.update(params.data);
});

Now since its registered in the Base prototype method it should be safe to remove the second binding from the SingleSelection.prototype.bind method.

In testing by removing the second binding it will only fire once as you would expect in the ajax case. I am not sure of the Ramifications of doing this though, @kevin-brown would you know if that is the proper fix.

@kevin-brown
Copy link
Member

@smoothlikejazz That should only need to be registered once, and I don't believe the ordering matters.

Feel free to submit a pull request which drops it from the SingleSelection.

@smoothlikejazz
Copy link

Okay great thanks @kevin-brown will do

@joanebrown
Copy link

@smoothlikejazz Hi! I still have this problem with the Select2 4.0.3. Your PR is not merged? In my case, the templateSelection its called four times...

BTW, who knows what's the diferrence between "select2.full" and "select2"?

Regards!!!

@joanebrown
Copy link

@kevin-brown There is any date for the 4.1.0 release? There are some workaround for this problem until the new release isnt yet ready?

@codybrouwers
Copy link

I am getting templateSelection called four times as well. Removing this listener brings it down to twice at least but is it going to get merged soon?

@Angelo8828
Copy link

+1 here. Experiencing the same problem.

@newmandani
Copy link

newmandani commented Aug 30, 2017

+1 Firing 8 times. I'll try to preserve this with logical value inverting first time to execute inside templateSelection function.

UPD: I've removed my function out of templateSelection and put it out to the external select2:select event.

$("#select2exampl").on('select2:select', function(selection){

        addPassengerAJAX( selection.params.data.code );
});

This works for me and do not execute several times. It is happening because templateSelection holds not only select2:select action I think.

@ahabunreal
Copy link

I'm having the same problem from inside jquery modal/dialog overlay. 2x and 4x times stuff is calling, this makes select2 pretty useless. I'm using latest 4.0.5 ..

anyone working to fix this problem?

@alexweissman
Copy link
Contributor

It looks like @kevin-brown already gave his blessing for the change made in #4306, so I will add that to the 4.0.6 milestone.

@alexweissman
Copy link
Contributor

The fix (#4306) has been merged into develop for 4.0.6 release.

@mz-devbo
Copy link

+1 Firing 8 times. I'll try to preserve this with logical value inverting first time to execute inside templateSelection function.

UPD: I've removed my function out of templateSelection and put it out to the external select2:select event.

$("#select2exampl").on('select2:select', function(selection){

        addPassengerAJAX( selection.params.data.code );
});

This works for me and do not execute several times. It is happening because templateSelection holds not only select2:select action I think.

This is the right way, thank you!

@rabih9780
Copy link

I am still having this problem with the latest version of select2. any hints on how i can fix this?

@Codename2200
Copy link

I'm having this issue right now. I'm using: Select2 4.1.0-beta.1

@ahabunreal
Copy link

I'm having this issue right now. I'm using: Select2 4.1.0-beta.1

Yep.. still seeing it to..

@estebansa19
Copy link

Solution of @newmandani is working fine, thanks!

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

No branches or pull requests