From a2ce88d094e6d962bca04296b9c54bef99d9ec59 Mon Sep 17 00:00:00 2001 From: Alicia Date: Thu, 4 Apr 2024 14:34:23 -0600 Subject: [PATCH] Solve event deprecation and missing target --- app/javascript/controllers/places_controller.js | 6 ++++-- app/javascript/packs/application.js | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/javascript/controllers/places_controller.js b/app/javascript/controllers/places_controller.js index d9c2cebe5..0f9a9ac90 100644 --- a/app/javascript/controllers/places_controller.js +++ b/app/javascript/controllers/places_controller.js @@ -109,8 +109,10 @@ export default class extends Controller { }) function success (position) { - document.getElementById('search_lat').value = position.coords.latitude; - document.getElementById('search_lon').value = position.coords.longitude; + if (document.getElementById('search_lat') && document.getElementById('search_lon')) { + document.getElementById('search_lat').value = position.coords.latitude; + document.getElementById('search_lon').value = position.coords.longitude; + } } if(!navigator.geolocation) { diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index f25ed6f99..91b0ee208 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -17,10 +17,12 @@ ActiveStorage.start() import "controllers" window.initMap = function (...args) { - const event = document.createEvent("Events") - event.initEvent("google-maps-callback", true, true) - event.args = args - window.dispatchEvent(event) + const event = new CustomEvent("google-maps-callback", { + detail: args, + bubbles: true, + cancelable: true + }); + window.dispatchEvent(event); } document.addEventListener("turbo:load", function (event) {