From 6ed74b2bc189bf79582a54868db8bbb277e9357a Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 17 Jan 2024 17:24:24 +1100 Subject: [PATCH 1/2] 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). --- app/webpacker/js/hotkeys.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/webpacker/js/hotkeys.js b/app/webpacker/js/hotkeys.js index 6a2c3a7b12..9b14d66cf4 100644 --- a/app/webpacker/js/hotkeys.js +++ b/app/webpacker/js/hotkeys.js @@ -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(); }); From b4f1709dcdefffe1984458300179672898733f11 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 17 Jan 2024 17:25:24 +1100 Subject: [PATCH 2/2] Remove console.log Oops. --- app/webpacker/controllers/tom_select_controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/app/webpacker/controllers/tom_select_controller.js b/app/webpacker/controllers/tom_select_controller.js index b9bc433f5c..2a3792d88e 100644 --- a/app/webpacker/controllers/tom_select_controller.js +++ b/app/webpacker/controllers/tom_select_controller.js @@ -5,7 +5,6 @@ export default class extends Controller { static values = { options: Object, placeholder: String }; connect(options = {}) { - console.log(this.element, this.placeholderValue); this.control = new TomSelect(this.element, { maxItems: 1, maxOptions: null,