hungle00/rondo_form

Use with standard rails form helpers

Closed this issue · 1 comments

Hello! Thanks for the gem.
From the description I understand that this gem is exactly what I need. I struggle a lot with adding additional form fields.
But I can't adapt the code to standard rail's form helpers.

I simplified a view and even not using a partials, but can't figure out how the link to add and remove associations should look like:

= form_with(model: [@user, @invoice]) do |form|
  .flex.flex-col
    = form.label :invoice_number, 'Invoice number'
    = form.text_field :number, class: "text-field"
       .......

    .my-4{data: {controller: "nested-rondo", "nested-rondo-field-class-value" => "line-item-form"}}
      %div{data: {"nested-rondo-target" => "fieldContain"}}
        %div{class: "line-item-form"}
          = form.fields_for :line_items do |line_item_form|
            = line_item_form.label :name, "service or product"
               .....
            = line_item_form.text_field :quantity, class: "text-field"
        
        = link_to_add_association "Add line item" **???**
        = link_to_remove_association "Remove Task"  **???**

I was using a partials and now I don't and probably this has very simple solution.
Can you please give some clue for how it should like with standard form helpers.

update oh..m nevermind, I installed simple forms, made everything using it and then reverse engineered it back to standard rails' helpers, now it works.
my star and my heart goes to you

Thank you for star my repo and creating this issue!
In case you or others need it, this is the code from my side project using Rails standard form.
In creating project form:

<%= form_with(model: project) do |form| %>
  <div class="field">
    <div class="control my-2">
      <%= form.label :name, style: "display: block" %>
      <%= form.text_field :name, class: "input", autofocus: true %>
    </div>

    <h3 class="is-size-5">Tasks</h3>

    <div class="my-2" data-controller="nested-rondo" data-nested-rondo-field-class-value="control">
      <div data-nested-rondo-target="fieldContain">
        <%= form.fields_for :tasks do |task| %>
          <%= render "task_fields", f: task %>
        <% end %>
      </div>
      <div class="links">
        <%= link_to_add_association "Add Task", form, :tasks %>
      </div>
    </div>

    <div class="control">
      <%= form.submit "Create", class: "button is-info" %>
    </div>
  </div>
<% end %>

In _task_fields partial:

<div class="control">
  <%= f.text_field :title, class: "input" %>
  <%= f.check_box :completed, class: "checkbox" %>
  <%= link_to_remove_association "Remove Task", f %>
</div>