miguelgrinberg / turbo-flask

Integration of Hotwire's Turbo library with Flask.
MIT License
301 stars 35 forks source link

Events don't fire #25

Closed pandermatt closed 2 years ago

pandermatt commented 2 years ago

Hello

$(document).on('turbo:render', function( e ) {
        console.log('hey')
});

This will result in no output, but the content of the website changes. Are there any other events to use upon a replace?

Thanks

miguelgrinberg commented 2 years ago

I'm not 100% sure of this, but I think it should be $('html').on('turbo:render', ...). The events are emitted on the <html> element of the document, not the document itself.

pandermatt commented 2 years ago

Sadly, this also emits no event. I also tried other events, but none are triggered.

miguelgrinberg commented 2 years ago

I really have no control over this, it is all handled by the turbo library.

I did a quick test to confirm that events are dispatched, and they are. I added the following to my "todos" example:

    <script>
      document.addEventListener('turbo:submit-start', () => console.log('submit-start'));
      document.addEventListener('turbo:submit-end', () => console.log('submit-end'));
    </script>

These work fine, so it is not a dispatching problem. My guess is that the event doesn't fire because it isn't supposed to fire in the situation you are in. I suggest asking on Stack Overflow or a hotwired forum.

pandermatt commented 2 years ago

Thank you very much!