Skip to content

Instantly share code, notes, and snippets.

@argent-smith
Created October 4, 2012 19:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save argent-smith/3835854 to your computer and use it in GitHub Desktop.
Save argent-smith/3835854 to your computer and use it in GitHub Desktop.
a hack attaching select2 to best_in_place
# connecting select2 to the appropriate hooks:
#
# hard case: best_in_place's select
$ ->
# first, find the mount point
$('body').on 'best_in_place:activate', '.best_in_place', ->
# second, attach empty update() to `this` to screen the downstream calls
# which otherwise will cause an error
@update = ->
# now unbind `blur` from the <select> and bind it to the downstream
# best_in_place's handler; this prevents the immediate select2's
# destruction since clicking on it would cause `blur` on the downstream
# best_in_place
$(@).find('select').select2()
.unbind('blur').bind('blur', {editor: @}, BestInPlaceEditor.forms.select.blurHandler)
# simple case: attach to a usual select
$ ->
$('.select2').select2()
@strickland84
Copy link

Great work man, really helpful!

@bsa7
Copy link

bsa7 commented Jan 24, 2014

Hi!
Can you explain, how i can use it with rails?
In my example - i have best_in_place control which work fine. But whenewer i put code for select2 the control broke. It simple clear data, but nothing to do more.
With best regards.
Sorry for silly question.
I activate bip in function:

-------------------------

doc_ready = ->
jQuery ($) ->
$(".best_in_place").best_in_place()

so, can i modify this for use with select2?

@futura
Copy link

futura commented Feb 18, 2014

Exactly what I needed! Thanks!

@arunwrc
Copy link

arunwrc commented Jun 10, 2015

everything works fine, but how to focus on that select2 element, am using a scrollable form(horizontal). When i choose an option from select2, it scrolls to the begining of that form

@davidleandro
Copy link

Thanks! Works great!

@Alagaesia93
Copy link

Hi! I've got a problem because I've a multiple select2 box, and it doesn't show all the selected values! Do you have any ideas?

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