nathanvda/cocoon — pull request #82 by porecreat (2012-08-28 17:26:04+00:00)
Title: Relative node selection

Hi,

Here's a solution for issue #81 I've submitted today.

This allows the use of jquery traversal (`closest`, `next`, `parent`, `children`, etc. everything available here : http://api.jquery.com/category/traversing/tree-traversal/) to select insertion node.

I've personnaly used it for 2 levels table nested forms.

The link to add second level fields has this syntax :

link_to_add_association '', f, :filesystems, {data: {:'association-insertion-traversal' => 'closest', :'association-insertion-node' => '#node_filesystems', :'association-insertion-method' => :append}}

Which points to the closest `#node_filesystems` id in the DOM tree.

I haven't found any other solution to do this in your upstream version.

This works perfectly in my case. Nothing changes when `data-association-insertion-traversal` is not used (global selection).

I haven't added specs since it's a Javascript only change.

The readme is updated but my English is not perfect so it's better to review it ;o)

Regards,

Gauthier