-
Notifications
You must be signed in to change notification settings - Fork 64
Issue with rails_ujs #12
Comments
This problem because of https://github.com/kossnocorp/jquery.turbolinks/blob/master/src/jquery.turbolinks.coffee#L27 and this: #8. Any ideas how to fix it? |
Look like I need to hack |
Are you thinking of preventing double handlers by checking if a function has already been binded?
|
Whoever wants to test if this prevents double submits, you can use:
|
-1 on this... changing jQuery behavior (supressing double-binding) seems like a very bad idea. If events are double-fired, they are most likely bound twice. If they are bound twice, they're most likely executed twice because you have your script tags in Try moving all your scripts to |
Double-firing in the referred case happens because it's binded in jQuery(->) which gets re-evaluated every page:change |
Rails-ujs doesn't work inside a I suspect that you only need change your load order to this: <html>
<head>
<script src='jquery.js'></script>
<script src='jquery.turbolinks.js'></script>
<script src='jquery_ujs.js'></script>
<!-- other scripts here -->
<script src='turbolinks.js'></script>
</head>
<body>
...
</body>
</html> Note that it's inside |
I was referring to #8. That issue is the reason jquery.turbolinks started clearing the document events on fetch:
Which is why your code above will stop working after the first fetch. My patch removes the |
Why is the duplicate check of If you bind your delegates (eg, |
This reverts the change introduced in kossnocorp#8. This fixes kossnocorp#14 and kossnocorp#12. The code `$(document).off(undefined, '**')` breaks 3rd-party script behavior where events are delegated outside a `document.ready` wrapper, like Rails's jquery_ujs. For instance, having code that looks like this will fail after navigating to a second page: // [A] $(document).on('click', 'button', function() { ... }) ...this is exactly how scripts like jquery_ujs binds its events, and is prescribed in jQuery's documentation for [fn.live]. To get around it, some people may misguidedly wrap it in a `document.ready` wrapper like so. This is inefficient: events will then be bound and un-bound repeatedly as you navigate through pages. // [B] $(function() { $(document).on('click', 'button', function() { ... }) }); Therefore, [A] should be the recommended solution. This fix makes [A] work again, but breaks the behavior of [B]. [fn.live]: http://api.jquery.com/live/
I think this can be closed now with 1.0.0-rc2. :) |
Delete link (data-method=delete data-confirm="Yes?") + rails ujs + turbolink'd page (after page change) = fail
Likely related to how rails_ujs binds events
The text was updated successfully, but these errors were encountered: