mkhairi / materialize-sass

Materializecss rubygem for Rails Asset Pipeline / Sprockets
http://materialize.labs.my/
MIT License
806 stars 243 forks source link

modal-trigger doesn't work whit turbolinks #162

Closed dbarison closed 6 years ago

dbarison commented 6 years ago

<button data-target="modal1" class="btn modal-trigger">Modal</button>

this doesn't work with turbolinks. Modal doesn't open

nikolaokonesh commented 6 years ago

@dbarison

$(document).on "turbolinks:load", -> $('#modal1').modal()

basicBrogrammer commented 6 years ago

I'm having a similar problem. It works if it is the first page load. However, if you navigate away and back to a page containing a modal it will not trigger the second time. :/ I'm using the turbolinks:load event listener.

esthersweon commented 6 years ago

Manually adding JQuery to trigger the modal opening works for me:

$(document).on('turbolinks:load', function() {
  $('.modal').modal();
  $('.modal-trigger').on('click', function() {
    $('.modal').modal('open');
  })
})

With that said, this seems like a workaround, and I'm wondering if there should be another JQuery event we are listening to in addition to turbolinks:load that would fix this problem.

arthurlinhares commented 6 years ago

@basicBrogrammer, I was having pretty much the same problem and managed to fix it by resetting Materialize's modal count before initializing the modals:

$(document).on('turbolinks:load', function() {
  M.Modal._count = 0;
  $('.modal').modal();
});
geniuskidkanyi commented 6 years ago

the resetting model count works for me

Goku-San commented 6 years ago

Thanks @arthurlinhares it works...

sakshamgupta05 commented 5 years ago

Thank you! so much worked like charm