mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Unfortunately it doesn't work for Angular forms. I'm not sure if there's a way to trigger an angular submit.
21 lines
679 B
JavaScript
21 lines
679 B
JavaScript
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();
|
|
}
|
|
});
|