Location cannot be re-geocoded after update in entity browser

Created on 13 October 2024, 6 months ago

Problem/Motivation

Discovered in Localgov Drupal directories, though I think this will occur anywhere using an entity browser to select geo entities where the Geo could be edited inside the entity browser. It does not occur when editing the Geo_entity under admin -> content -> locations / geos.

Original issue on See: https://github.com/localgovdrupal/localgov_geo/issues/133

Create a new directory venue with a brand new geo entity as a location. This should geocode the map pin.
Then edit said directory venue, and edit the location (not delete and replace). Clear out the address and try to add a new one. Whilst the autocomplete does replace it, the leaflet map pin and lat / lon fields are not updated.
I have seen this with both directories and events, and with fresh localgov drupal install and BHCC code base.
Happens regardless on if using leaflet or geofield_map for the map pin.

This has been seen in Directories and Events, but works fine when editing the geo_entity directly.
Posting here whilst investigating if it is a specific configuration issue with Directories and events.

Steps to reproduce

See linked Github issue above.

Proposed resolution

I managed to trace this to js/geocode-leaflet.js and the corresponding js/geocode-geofield.js. They are trying to attach javascript to a form with id geo-entity-address-edit-form which will have been changed to add a unique string at the end on subsequent loads eg. geo-entity-address-edit-form-uqlfl1mbwkm.
once('geoEntityGeocodeLeaflet', document.getElementById(formId)).forEach(function (form) {
This is fetching the formId from drupalSettings.geoEntityGeocode.leaflet which gives

{geo-entity-address-edit-form: 'leaflet-map-widget-geo-entity-address-35-location--6NyaxaYSeuE'}

It looks like the key needs to updated like the value side to reflect the unique ID of the form.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom andybroomfield

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @andybroomfield
  • 🇬🇧United Kingdom andybroomfield

    Changing
    once('geoEntityGeocodeLeaflet', document.getElementById(formId)).forEach(function (form) {
    to
    once('geoEntityGeocodeLeaflet', document.querySelectorAll('form[id^="' + formId + '"]')).forEach(function (form) {
    works. Might not be the most performant though.

  • 🇳🇱Netherlands ekes

    I'm just trying to recreate this. Are there some steps I could follow?

  • 🇬🇧United Kingdom andybroomfield

    See the linked Github issue above:

    1. Create a new directory venue with a brand new geo entity as a location. This should geocode the map pin.
    2. Then edit said directory venue, and edit the location (not delete and replace).
    3. Clear out the address and try to add a new one. Whilst the autocomplete does replace it, the leaflet map pin and lat / lon fields are not updated.
Production build 0.71.5 2024