Problem/Motivation

Leaflet field form map widget is not loading first time editing new/existing child node from inline-entity-form UI

Leaflet map doesn't load correctly first time when when editing a new or existing node from within a parent node using inline-entity-form.

On first access it shows none of the form controls i set in configuration and doesnt center the map to the coords set in the field configuration. If I cancel the current operation and re-enter the same node, the map centers and controls correctly.

This issue affects the leaflet field form widget accessed from inline-entity-forms. This issue does not affect the leaflet field form widget in the code node editor.

Steps to reproduce

  1. Create a content type A and add a leaflet map field.
  2. Configure the field with center coordinates and turn on ALL controls.
  3. Create a parent content type B with an multi-entity-ref field pointing to content type A
  4. Set the form config for the entityref content type A field to use IEF widget
  5. Create new node from content type A note form and display work as expected through the node/edit URL
  6. Create new node from content type B and add a new node of type A to it.
  7. "Create new node" of content type A within content type B.
  8. Note that the Leaflet map does not center and there are no controls.
  9. Cancel the operation.
  10. Reselect "create new node" and note that the map works ok on second load
  11. Enter any data, pick a known map position, save the child and parent nodes
  12. Reload the content type B page.
  13. Edit the new child node through the IEF interface.
  14. Note that the Leaflet map does not center and there are no controls.
  15. Reaccess the existing child node through the IEF interface.
  16. Note that the leaflet map centers and the controls are rendered correctly.

Proposed resolution

Current workaround: the first operation through the IEF interface fails. I have to cancel the first attempt and retry. Eliminate the redundant stage so that the map loads correctly first time.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Syntapse created an issue. See original summary.

Syntapse’s picture

Title: Leaflet form map is not loading first time editing new/existing child node from inline-entity-form UI » Leaflet field form map widget is not loading first time editing new/existing child node from inline-entity-form UI
Issue summary: View changes
itamair’s picture

Status: Active » Needs work

Yes ... I have experiencing this too, and inspected ... but I couldn't find any viable solution.
Any solid fixing patch (strictly not regressive and Drupal/php coding standards compliant) will be super welcome ...

matthiasm11’s picture

Installing the patch from #218 of https://www.drupal.org/project/drupal/issues/1988968 did the trick in my case. (leaflet widget in an "add another paragraph")

tobiasb’s picture

Status: Needs work » Needs review
StatusFileSize
new529 bytes

I believe I have a solution / workaround for #1988968: Drupal.ajax does not guarantee that "add new JS file to page" commands have finished before calling said JS. I my case map.pm was not initialized in quick-edit. But when I load geoman already with leaflet-drupal, the geoman is initialized.

And I added more deps to the leaflet-widget lib.

In the use case, hide map when empty + quickedit then you need the solution of #1988968: Drupal.ajax does not guarantee that "add new JS file to page" commands have finished before calling said JS.

What I did not test is to load js from locally not from cdn.

nod_’s picture

Core issue is now fixed for 9.5+ branches :)