marinosoftware / active_storage_drag_and_drop

Provides a form helper to make it easy to make drag-and-drop file upload fields that work with Rails' Active Storage.
MIT License
92 stars 14 forks source link

Doesn't play nice with Turbolinks? #48

Open suan opened 4 years ago

suan commented 4 years ago

First off thanks for this library!

Looks like the JS for this library assumes the target element is already present on the page, at the time application.js is executed -- however this doesn't work with Turbolinks as application.js will only get executed on the very first request, and so if the dnd-target is not present until a later navigation, the library doesn't get activated.

Worse so, since the start status is cached, even attempts to force-call start() to bind after a turbolinks:load doesn't work.

Would be great to get some better Turbolinks integration given its been the default in Rails 5 and up...

IanGrantMarino commented 4 years ago

This should work fine with turbolinks. The start function adds listeners to the document that then check the event target and use that to find or initialize the form controllers so the form/drag and drop field can enter the dom at any time. The start status is cached to prevent adding the event listeners to the dom more than once.