Created
March 30, 2023 15:20
-
-
Save narath/f30dfde88e047c5810a2a44a81ee1c22 to your computer and use it in GitHub Desktop.
Stimulus JS TextArea Easy Submit with Cmd or Ctrl Enter
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 { Controller } from "@hotwired/stimulus" | |
export default class extends Controller { | |
submit() { | |
event.currentTarget.form.requestSubmit() | |
} | |
} |
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 url: tasks_url, method: :patch do |form| %> | |
<div> | |
<label for="tasks">Your tasks</label> | |
<%= text_area_tag :tasks, tasks, data: { controller: "textarea-autogrow easysubmit", action: "keydown.meta+enter->easysubmit#submit keydown.ctrl+enter->easysubmit#submit" } %> | |
</div> | |
<div> | |
<%= link_to "Cancel", tasks_url %> | |
<%= form.button "Save" %> | |
</div> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See a more complete form utilities here