Skip to content

Commit

Permalink
Solve event deprecation and missing target
Browse files Browse the repository at this point in the history
  • Loading branch information
aliciapaz committed Apr 4, 2024
1 parent 2b5fd2c commit a2ce88d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/javascript/controllers/places_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a2ce88d

Please sign in to comment.