Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Allow custom wrapper selector #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stsc3000
Copy link

Nested_form assumes that the element wrapping the blueprint has class="fields" by default. As this may conflict with existing css, the following may be used to add a custom wrapper selector:

<%= nested_form_for @task do |f| -%>
  <%= f.text_field :name %>
  <table id="tasks">
    <%= f.fields_for :milestones, :wrapper => false do |milestone_form| %>
      <tr class="milestones-wrapper">
        <td><%= milestone_form.text_field :name %></td>
        <td><%= milestone_form.link_to_remove "Remove" %></td>
      </tr>
    <% end %>
  </table>
  <p><%= f.link_to_add "Add new milestone", :milestones, 
                                            "data-target" => "#tasks", 
                                            "data-selector" => ".milestones-wrapper" %></p>
<% end %>

If no custom selector is given, ".fields" is used. After rendering the blueprint, addFields or its prototype equivalent adds a data-nested-wrapper attribute to the wrapper so the remove links can find the wrapper, as they did with ".fields" previously.

Implemented for the prototype and jquery variants along with specs.
Readme is updated, too.

@douglasresende
Copy link

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants