Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
Last active July 5, 2022 09:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save julianrubisch/7773e67b2ab8184f16660188803c983f to your computer and use it in GitHub Desktop.
Save julianrubisch/7773e67b2ab8184f16660188803c983f to your computer and use it in GitHub Desktop.
StimulusReflex Form Reset Controller
<%= form_with(model: model, data: {controller: "reflex-form", reflex_form_reflex: "ExampleReflex#submit"}) do |form| %>
<%= form.button data: {action: "click->reflex-form#submit"} %>
<% end %>
import ApplicationController from './application_controller'
export default class extends ApplicationController {
submit (e) {
e.preventDefault()
this.stimulate(this.data.get('reflex')).then(() => {
this.element.reset()
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment