Skip to content

Instantly share code, notes, and snippets.

@usutani
Created October 16, 2021 01:51
Show Gist options
  • Save usutani/6d0e50e64d807bafd683af1c6b1d2530 to your computer and use it in GitHub Desktop.
Save usutani/6d0e50e64d807bafd683af1c6b1d2530 to your computer and use it in GitHub Desktop.
stimulus reset_form フォームのリセット
bin/rails g stimulus reset_form
<% form_data = { controller: "reset-form", action: "turbo:submit-end->reset-form#reset" }%>
<%= form_with model: @message, data: form_data do |form| %>
  <%= form.text_field :body %>
  <%= form.submit %>
<% end %>
import { Controller } from "@hotwired/stimulus"
// Connects to data-controller="reset-form"
export default class extends Controller {
reset() {
this.element.reset()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment