From 4d3669ef2a9912bc18f4e443e15c778206ddedd7 Mon Sep 17 00:00:00 2001 From: Daphne Gold Date: Tue, 11 Mar 2025 15:37:31 -0700 Subject: [PATCH] Fix date picker and modal --- app/app/javascript/application.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/app/javascript/application.js b/app/app/javascript/application.js index d7097c45..e4bc28a5 100644 --- a/app/app/javascript/application.js +++ b/app/app/javascript/application.js @@ -8,6 +8,14 @@ import "@uswds/uswds" import components from "@uswds/uswds/src/js/components" let initialLoad = true +const reinitializeUSWDS = () => { + const target = document.body + Object.keys(components).forEach((key) => { + const behavior = components[key] + behavior.on(target) + }) +} + document.addEventListener("turbo:load", () => { if (initialLoad) { // initial domready is handled by `import "uswds"` code @@ -15,11 +23,11 @@ document.addEventListener("turbo:load", () => { return } - const target = document.body - Object.keys(components).forEach((key) => { - const behavior = components[key] - behavior.on(target) - }) + reinitializeUSWDS() +}) + +document.addEventListener("turbo:render", () => { + reinitializeUSWDS() }) document.addEventListener("turbo:frame-render", () => {