Ensure keyboard shortcut fires event handlers correctly

A StimulusReflex form handler was being ignored, resulting in an error.

Note that this method can support angular forms, the submit buttons just need to be updated to type='submit' (why they are not already boggles me).
This commit is contained in:
David Cook
2024-01-17 17:24:24 +11:00
parent bf649b2f96
commit 6ed74b2bc1

View File

@@ -13,8 +13,9 @@ hotkeys.filter = function (event) {
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();
}
// Simulate a click on the first available submit button. This seems to be the most robust option,
// ensuring that event handlers are handled first (eg for StimulusReflex). If there's no submit
// button, nothing happens (eg for Angular forms).
const submit = form && form.querySelector('input[type="submit"], button[type="submit"]');
submit && submit.click();
});