Skip to content

Instantly share code, notes, and snippets.

@narath
Created March 30, 2023 15:20
Show Gist options
  • Save narath/f30dfde88e047c5810a2a44a81ee1c22 to your computer and use it in GitHub Desktop.
Save narath/f30dfde88e047c5810a2a44a81ee1c22 to your computer and use it in GitHub Desktop.
Stimulus JS TextArea Easy Submit with Cmd or Ctrl Enter
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
submit() {
event.currentTarget.form.requestSubmit()
}
}
<%= 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 %>
@narath
Copy link
Author

narath commented Mar 30, 2023

See a more complete form utilities here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment