From f20a1b5398fe4a317d8a4f1d5da207847c43518d Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 20 Sep 2024 18:55:08 -0700 Subject: [PATCH] Oops, fix locale form with Turbo pageloads Before this change, this would only work on the first pageload, and fail after doing a Turbo page navigation. Now, it works all the time! --- app/javascript/application.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/javascript/application.js b/app/javascript/application.js index 48bb4030..400e8b8a 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1,5 +1,6 @@ import "@hotwired/turbo-rails"; -document.getElementById("locale").addEventListener("change", function () { +document.addEventListener("change", (e) => { + if (!e.target.matches("#locale")) return; document.getElementById("locale-form").submit(); });