Location cannot be re-geocoded after update in entity browser
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3480411. --> Reported by: [andybroomfield](https://www.drupal.org/user/636756) Related to !11 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>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 -&gt; content -&gt; locations / geos.</p> <p>Original issue on See: <a href="https://github.com/localgovdrupal/localgov_geo/issues/133">https://github.com/localgovdrupal/localgov_geo/issues/133</a></p> <blockquote><p>Create a new directory venue with a brand new geo entity as a location. This should geocode the map pin.<br> 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.<br> I have seen this with both directories and events, and with fresh localgov drupal install and BHCC code base.<br> Happens regardless on if using leaflet or geofield_map for the map pin.</p> <p>This has been seen in Directories and Events, but works fine when editing the geo_entity directly.<br> Posting here whilst investigating if it is a specific configuration issue with Directories and events.</p></blockquote> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>See linked Github issue above.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>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.<br> <code>once('geoEntityGeocodeLeaflet', document.getElementById(formId)).forEach(function (form) {</code><br> This is fetching the formId from drupalSettings.geoEntityGeocode.leaflet which gives </p> <pre>{geo-entity-address-edit-form: 'leaflet-map-widget-geo-entity-address-35-location--6NyaxaYSeuE'}</pre><p> It looks like the key needs to updated like the value side to reflect the unique ID of the form.</p>
issue