๐งโโ๏ธMulti-Step Form Wizard
Break long forms into manageable steps
Overview
Installation & Setup
1. Create the Form View
<div data-controller="wizard" class="space-y-6">
<%= form_with model: @model, local: true, html: { class: "space-y-4" } do |f| %>
<!-- Step 1 -->
<div data-wizard-target="step" class="card bg-base-100 shadow p-6">
<div class="form-control">
<%= f.label :first_name, class: "label" %>
<%= f.text_field :first_name, class: "input input-bordered" %>
</div>
<div class="mt-4 flex justify-end">
<%= button_tag "Next", type: "button",
data: {
action: "click->wizard#goToNext",
next_step: "1"
},
class: "btn btn-primary" %>
</div>
</div>
<!-- Step 2 -->
<div data-wizard-target="step" class="card bg-base-100 shadow p-6 hidden">
<div class="form-control">
<%= f.label :last_name, class: "label" %>
<%= f.text_field :last_name, class: "input input-bordered" %>
</div>
<div class="mt-4 flex justify-between">
<%= button_tag "Previous", type: "button",
data: {
action: "click->wizard#goToPrevious",
previous_step: "1"
},
class: "btn btn-outline" %>
<%= button_tag "Next", type: "button",
data: {
action: "click->wizard#goToNext",
next_step: "2"
},
class: "btn btn-primary" %>
</div>
</div>
<!-- Step 3 -->
<div data-wizard-target="step" class="card bg-base-100 shadow p-6 hidden">
<div class="form-control">
<%= f.label :email, class: "label" %>
<%= f.email_field :email, class: "input input-bordered" %>
</div>
<div class="mt-4 flex justify-between">
<%= button_tag "Previous", type: "button",
data: {
action: "click->wizard#goToPrevious",
previous_step: "2"
},
class: "btn btn-outline" %>
<%= f.submit "Submit", class: "btn btn-success" %>
</div>
</div>
<% end %>
</div>2. Create the Stimulus Controller
Usage
Best Practices
Troubleshooting
Last updated