Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

nested_form works wrong with turbolinks #220

wants to merge 1 commit into


None yet
5 participants

Event handlers are executed multiply times

ccmcbeck commented Jan 3, 2013


I was having the same problem and this fix worked for me.


lest commented Jan 3, 2013

I guess #145 could solve turbolinks issues. Could you please test it?

ccmcbeck commented Jan 3, 2013

@lest, this commit does fix my problem of multiple events firing

gem 'nested_form', ref: '0607c80', git: 'https://github.com/fxposter/nested_form.git'

Also, i'm seeing nested:fieldAdded firing properly in 0607c80 which wasn't happening in either of these commits

gem 'nested_form', '0.3.1'
gem 'nested_form', '0.3.1', git: 'https://github.com/leoniddinershtein/nested_form.git'

Is there a more recent commit that I should be using / testing against?

FWIW, my app also uses simple_form, client_side_validations, backbone, bootstrap (desktop), and jquery_mobile (mobile). I use nested_form on both desktop and mobile.


lest commented Jan 3, 2013

@ccmcbeck Thanks for testing <3

I'm going to rebase #145 and push it to the master branch.

ccmcbeck commented Jan 3, 2013

Thanks to you for working this issue. If you need additional assistance, just let me know.


lest commented Jan 4, 2013

@ccmcbeck I've pushed jquery code changes from #145 to the master branch of nested_form. Could you please confirm that it's working with turbolinks now?

ccmcbeck commented Jan 5, 2013

@lest, when i use this

gem 'nested_form', branch: 'master', git: 'https://github.com/ryanb/nested_form.git'

The edit and delete UJS actions work fine, however only the nested:fieldAdded fires

When I revert back to

gem 'nested_form', ref: '0607c80', git: 'https://github.com/fxposter/nested_form.git'

Both events fire. I checked it in the Safari Web Inspector timeline and with this code:

$(document).on 'nested:fieldAdded', ->
  console.log 'nested:fieldAdded'
$(document).on 'nested:fieldRemoved', ->
  console.log 'nested:fieldRemoved'

lest commented Jan 9, 2013

@ccmcbeck Weird... I'll try to test it and provide a fix. It'll be very helpful to have a test application reproducing this issue.

It is weird. I will look into it further and isolate the code to see if it's my error.

firedev commented Feb 16, 2013

I am having this issue as well, guess turbolinks can wait. Everytime I use them sooner or later run into one issue or another.

+1, also just realized that turbo-links was causing the link_to_add event to fire multiple times.


lest commented Jul 1, 2013

@ndbroadbent Any ideas about the best solution for adding event handlers and being compatible with turbolinks?

@lest, I looked into this a little further, and figured out how to make it work. We've got to follow the advice given in the "Evaluating script tags" section of the turbolinks README.

As a rule of thumb when switching to Turbolinks, move all of your javascript tags inside the head and then work backwards, only moving javascript code back to the body if absolutely necessary.

Moving my javascript to the head of the layout solved the problem.


lest commented Jul 1, 2013

Thanks @ndbroadbent.

Closing as it seems there is no need to make any changes to nested_form.

@lest lest closed this Jul 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment