Skip to content

Forms nested multiple levels #76

@karianne

Description

@karianne

I'm trying to use this gem to add a two-level structure: Theme --(has many)--> ThemeSection --(has_many)--> ThemeSectionItem. However, it seems that I'm running into a bug where " is not encoded correctly, since I get this html when trying to add a ThemeSection:

<div id="all_sections">
              <div class="section_container added-by-vanilla-nested">
  <p class="form-group form-field string required theme_theme_sections_title"><label class="control-label form-field__label string required" for="theme_theme_sections_attributes_1700576891368_title"><abbr title="påkrevd">*</abbr> Tittel</label><span class="form-field__control-wrapper"><input class="form-control form-field__control string required" required="required" aria-required="true" type="text" name="theme[theme_sections_attributes][1700576891368][title]" id="theme_theme_sections_attributes_1700576891368_title"></span></p>
  <input value="0" autocomplete="off" type="hidden" name="theme[theme_sections_attributes][1700576891368][_destroy]" id="theme_theme_sections_attributes_1700576891368__destroy"><a class=" vanilla-nested-remove " data-undo-text="Undo" data-undo-link-classes="">Remove theme section</a>
  <div class="all_items">
      </div>
  <a class=" vanilla-nested-add " data-container-selector=".all_items" data-html="<div id=" item_container"="">
  <p class="form-group form-field integer optional theme_theme_sections_theme_section_items_itemable_id"><label class="control-label form-field__label integer optional" for="theme_theme_sections_attributes_1700576891368_theme_section_items_attributes_1700576891368_itemable_id">Itemable</label><span class="form-field__control-wrapper"><input class="form-control form-field__control numeric integer optional" type="number" step="1" name="theme[theme_sections_attributes][1700576891368][theme_section_items_attributes][1700576891368][itemable_id]" id="theme_theme_sections_attributes_1700576891368_theme_section_items_attributes_1700576891368_itemable_id"></span></p>
  <input value="0" autocomplete="off" type="hidden" name="theme[theme_sections_attributes][1700576891368][theme_section_items_attributes][1700576891368][_destroy]" id="theme_theme_sections_attributes_1700576891368_theme_section_items_attributes_1700576891368__destroy"></a><a class=" vanilla-nested-remove " data-undo-text="Undo" data-undo-link-classes="">Fjern denne artikkelen</a>
</div>" data-method-for-insert="append"&gt;Add ThemeSectionItem
</div>

(note the broken data-method-for-insert at the bottom, which should have been a part of the div added by vanilla-nested)

Is this gem even supposed to be used with two levels?


For reference, here's my form ERB:

_form.html.erb:

<%= simple_form_for(theme) do |f| %>
....
<%= field_set_tag 'Sections' do %>
      <%= link_to_add_nested(f, :theme_sections, '#all_sections') %>
      <div id="all_sections">
        <%= f.simple_fields_for :theme_sections do |sf| %>
          <%= render 'theme_section_fields', form: sf %>
        <% end %>
      </div>
    <% end %>
    <%= f.button :submit, class: 'button--standalone' %>
<% end %>

theme_section_fields.html.erb:

<div class="section_container">
  <%= form.input :title %>
  <%= link_to_remove_nested(form, link_text: "Remove theme section") %>
  <div class="all_items">
    <%= form.simple_fields_for :theme_section_items do |sif| %>
      <%= render 'theme_section_item_fields', form: sif %>
    <% end %>
  </div>
  <%= link_to_add_nested(form, :theme_section_items, '.all_items') %>
</div>

theme_section_item_fields.html.erb:

<div id='item_container'>
  <%= form.input :itemable_id %>
  <%= link_to_remove_nested(form, link_text: "Remove item") %>
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions