Stimulus Controller to manage nested form fields
npm install stimulus-nested-formCredit goes to GoRails.com and
DriftingRuby
This assumes StimulusJS is already installed.
1. Add package yarn add stimulus-nested-form
2. Import package in your application
``javascript`
import NestedForm from "stimulus-nested-form"
application.register("nested-form", NestedForm)
` <%= f.fields_for :options do |ff| %>html
<%= f.fields_for :options, ProductOption.new, child_index: "NEW_RECORD" do |ff| %>
<%= render "product_options/option_fields", field: ff %>
<% end %>
<%= render "product_options/option_fields", field: ff %>
<% end %>
<%= link_to t("product_option.add"), "#",
class: "btn btn-link",
data: { action: "click->nested-form#add_association" } %>
<%= tag.div class: 'nested-fields', data: { new_record: field.object.new_record? } do %>
Publish new version
Install Microbundle if not present yet
npm -g install microbundle1. Run
yarn build
2. Update CHANGELOG.md
3. Run yarn publish`