Add keyboard shortcut to submit form in admin

Unfortunately it doesn't work for Angular forms. I'm not sure if there's a way to trigger an angular submit.
This commit is contained in:
David Cook
2023-12-29 14:56:44 +11:00
parent 50fb8466a9
commit 78e2311f59
2 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import hotkeys from "hotkeys-js";
// Enable hotkeys on form elements
hotkeys.filter = function (event) {
var tagName = (event.target || event.srcElement).tagName;
hotkeys.setScope(/^(INPUT|TEXTAREA|SELECT|BUTTON)$/.test(tagName) ? "input" : "other");
return true;
};
// Submit form
// Although 'enter' will submit the form in many cases, it doesn't cover elements such
// as select and textarea. This shortcut is a standard used across many major websites.
hotkeys("ctrl+enter, command+enter", function (event, handler) {
const form = event.target.form;
// If element has a non-angular form
if (form && !form.classList.contains("ng")) {
form.submit();
}
});

View File

@@ -1,6 +1,7 @@
import "controllers";
import "channels";
import "@hotwired/turbo";
import "../js/hotkeys";
import "../js/mrujs";
import "../js/matomo";
import "../js/moment";