Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Multiple Nested Fields

Simon Starr edited this page Jun 30, 2013 · 2 revisions

It is easy to have multiple nested fields on the same page. Instead of applying nestedFields() to the form, first put the elements (items, container, add, remove) inside a wrapper:

<!-- ERB view -->

<h2>Phones</h2>
<div id="phones">
  <div class="items">
    <%= f.nested_fields_for :phones do |f| %>
      <% ... %>
    <% end %>
  </div>
  <a href="#" class="add">add phone</a>
</div>

<h2>Addresses</h2>
<div id="addresses">
  <div class="items">
    <%= f.nested_fields_for :addresses do |f| %>
      <% ... %>
    <% end %>
  </div>
  <a href="#" class="add">add address</a>
</div>

Then apply nested fields to it:

// Javascript

$('#phones, #addresses').nestedFields();
Clone this wiki locally