RondoForm
Handle dynamic nested forms, same as Cocoon, but using StimulusJS
Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add rondo_form
Or inside the Gemfile add the following
$ gem 'rondo_form', '~> 0.2.1'
Run the installation task:
$ rails g rondo_form:install
Usage
For example, we have Project
model, which has has_many
relationship with Task
model:
rails g scaffold Project name:string description:string
rails g model Task description:string done:boolean project:belongs_to
Sample with SimpleForm
In your projects/_form
partial:
<%= simple_form_for(@project) do |f| %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :description %>
</div>
<h3 class="text-xl mt-4">Tasks</h3>
<div class="my-2" data-controller="nested-rondo">
<%= f.simple_fields_for :tasks do |task| %>
<%= render "task_fields", f: task %>
<%
…