mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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:
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user