mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
20
app/webpacker/js/hotkeys.js
Normal file
20
app/webpacker/js/hotkeys.js
Normal 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();
|
||||
}
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
import "controllers";
|
||||
import "channels";
|
||||
import "@hotwired/turbo";
|
||||
import "../js/hotkeys";
|
||||
import "../js/mrujs";
|
||||
import "../js/matomo";
|
||||
import "../js/moment";
|
||||
|
||||
Reference in New Issue
Block a user