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

failed in loading js after back button #169

Open
sondh5 opened this Issue Feb 8, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@sondh5
Copy link

sondh5 commented Feb 8, 2017

I am using select2 with ransack to multiple searching but it got a big problem.

My js file: search.js
$(document).on("turbolinks:load", function () { $("#q_city_matches_any").select2({ placeholder: I18n.t("js.city") }); });

My slim: index.html.slim

p.form-group= f.select :city_matches_any, @cities, {}, {class: "form-control", multiple: true}

application.js

  • //= require jquery
  • //= require jquery_ujs
  • //= require bootstrap-sprockets
  • //= require turbolinks
  • //= require select2
  • //= require i18n
  • //= require i18n.js
  • //= require i18n/translations
  • //= require_tree .

Its oke in normal case but problem happens when I move from index page to other page and click button back of browser to back to index page.

Normal case: https://gyazo.com/9ea59e58e5271cd27ff716e548f51f17
Issue: https://gyazo.com/3d8826be1b4f028760618e83e8d7b9cf

Thank you for your support!

@argerim

This comment has been minimized.

Copy link
Owner

argerim commented Mar 31, 2017

@hongsondhs can try with https://github.com/kossnocorp/jquery.turbolinks ? pls

@rjducker

This comment has been minimized.

Copy link

rjducker commented Feb 14, 2018

Hello! I Have same problem on rails 5. jquery.turbolinks is deprecated, this gem does not work with Turbolinks 5+

@rjducker

This comment has been minimized.

Copy link

rjducker commented Feb 15, 2018

This works for me:

$(document).on("turbolinks:before-cache", function() {
    $('.select2-input').select2('destroy');
});

(document).on('turbolinks:load',function(){
  $('.select2-input').select2();
});

Details here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.