Last active
July 5, 2022 09:18
-
-
Save julianrubisch/7773e67b2ab8184f16660188803c983f to your computer and use it in GitHub Desktop.
StimulusReflex Form Reset Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_with(model: model, data: {controller: "reflex-form", reflex_form_reflex: "ExampleReflex#submit"}) do |form| %> | |
<%= form.button data: {action: "click->reflex-form#submit"} %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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