makinacorpus / django-leaflet

Use Leaflet in your Django projects
GNU Lesser General Public License v3.0
713 stars 282 forks source link

Uncaught TypeError: document.getElementById(...) is null in leaflet.draw.i18n.js:3 #386

Open adamchainz opened 6 days ago

adamchainz commented 6 days ago

With this minimal template:

{% load leaflet_tags %}

{% leaflet_js plugins="forms" %}

...I see this error:

Uncaught TypeError: document.getElementById(...) is null
    <anonymous> http://localhost:8000/static/leaflet/draw/leaflet.draw.i18n.js:3
leaflet.draw.i18n.js:3:66

The issue is here:

...
if (withForms) {
    L.drawLocal.draw.toolbar.actions.title = JSON.parse(document.getElementById("draw-toolbar-actions-title").textContent);
    ...

The JavaScript finds withForms to be true, but the corresponding JSON script elements weren't don't exist because the relevant template had its with_forms set to falsey.