why isn't #select2 reloading after @ajax calls? #turbolinks?
because #turbolinks is the devil
turbolinks uses ajax to refresh pages, which means your default
$(document).ready( function(){})
syntax will not be reloaded. so you need to put whatever javascript methods you want reloaded after any change in a separate
$(document).on("page:load", init);
call. turbolink doc here and very helpful so answer here
update 834pm: that didn't work.
i'm getting this error:
Uncaught query function not defined for Select2 s2id_search_period_start
could be related to turbolinks page:change function, which might be repeating and adding additional divs as said in this post
UPDATE dec 9, 2014 9am:
still not working.
could it be because:
By default, select2 adds the select2-offscreen class to already initialized targets to hide them. By using the jQuery .not(selector) function I exclude them to target to fresh input fields only. source
?
this so article deals somewhat with the multi-select, although this issue is more about the css generated for the selected items.
HOLY SHIT. this worked.
$('#box-inner-search').html("<%= escape_javascript(render 'searches/control_panel') %>") $(".menu-select2-update").select2(); init();
although i was re-initialized select2 on page change, what did it was that i re-initialized it on the partial that i was rendering. probably what is happening is that on an ajax call, none of the jquery pages are being reloaded. that's a good thing because it would slow things down. instead, you should put any re-initializing on the unobtrusive javascript method. in other words, it is an opt-in method; js methods will not be loaded unless you specifically opt in via your js.erb file. good one, rails.
this article reminds you to add a loading indicator












