vestman / Select-or-Die

Yet another jQuery plugin to style select elements. Demo at http://vst.mn/selectordie/
MIT License
524 stars 133 forks source link

onChange events are shared between instance of selectOrDie #17

Closed phbou72 closed 9 years ago

phbou72 commented 9 years ago

I made a little jsFiddle to explain the bug : http://jsfiddle.net/Ls3mcvLu/6/

Select something on the first select. The onChange event is triggered as expected.

Then, select something on the second dropdown. The second dropdown trigger the onChange event and show the value selected on the first select? Notice there is no listener for the event on the second dropdown?

vestman commented 9 years ago

I'm on it!

swapnilmishra commented 9 years ago

@phbou72 @vestman This is not because of selection from second dropdown. Just click anywhere else and the event will be triggered. A possible hack/workaround I am using is this : http://jsfiddle.net/oktg53kv/

phbou72 commented 9 years ago

Ok. Clicking elsewhere does trigger the event. But, that still point out a bug in my opinion. Why is the onChange event triggered multiple type? Why not only when we select a new option?

I should not need to use a closure to check if a new option has been selected.

gerbenvandijk commented 9 years ago

I've fixed this issue guys:

Add this after line 384:

_private.blurSod($sod);

@phbou72 @vestman @swapnilmishra

// all : please ignore the above fix. It does fix the described behaviour, however it peaks my CPU usage completely and results in a hanging browser. Would you check this out @vestman ? Thanks :+1:

As far as I can see, the element should be unfocussed after selecting a new one. At the moment, this doesn't happen and when you click outside of the dropdown the event gets fired again. Adding the line above fixed it - but results in a conflict with the rest of the plugin (seems to be some kind of endless loop).

Hope it helps, would be great to get it fixed :+1:

vestman commented 9 years ago

Fixed, thanks for pointing this out, @phbou72! Since you're using the selectordie.min.js from vst.mn as an external resource you can check your original fiddle - http://jsfiddle.net/Ls3mcvLu/6/ - to check that it's working.

gerbenvandijk commented 9 years ago

:+1: thanks @vestman

phbou72 commented 9 years ago

Thanks a lot @vestman! It work perfectly!