Skip to content

Instantly share code, notes, and snippets.

@scottbarrow
Forked from julianrubisch/form.html.erb
Created October 3, 2020 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottbarrow/8fbb87c213e8c2d793d93baac894604d to your computer and use it in GitHub Desktop.
Save scottbarrow/8fbb87c213e8c2d793d93baac894604d 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