-
-
Save scottbarrow/8fbb87c213e8c2d793d93baac894604d to your computer and use it in GitHub Desktop.
StimulusReflex Form Reset Controller
This file contains hidden or 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 hidden or 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