Skip to content

Commit 0838db0

Browse files
committed
fix: Fix the div ids to work with admin inlines
1 parent 0015b6d commit 0838db0

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
-------------------
88

99
- Set a default max zoom in leaflet.forms _setView to avoid an error.
10+
- Fix the div ids to work with admin inlines.
1011

1112

1213
0.21.0 (2017-02-28)

leaflet/forms/widgets.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ def render(self, name, value, attrs=None):
5555
if self.geom_type == 'GEOMETRY':
5656
attrs['geom_type'] = 'Geometry'
5757

58-
map_id = slugify(attrs.get('id', name)).replace('-', '_') # JS-safe
58+
map_id_css = slugify(attrs.get('id', name)) # id need to have - for the inline formset to replace the prefix
59+
map_id = map_id_css.replace('-', '_') # JS-safe
5960
attrs.update(id=map_id,
61+
id_css=map_id_css,
6062
module='geodjango_%s' % map_id,
61-
id_map=map_id + '_map',
63+
id_map=map_id_css + '-map',
6264
id_map_callback=map_id + '_map_callback',
6365
loadevent=loadevent,
6466
modifiable=self.modifiable,

leaflet/templates/leaflet/admin/widget.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{% endblock vars %}
2727

2828
{% block map %}
29-
<div id="{{ id }}_div_map">
29+
<div id="{{ id_css }}-div-map">
3030
{{ block.super }}
3131
</div>
3232
{% endblock map %}

leaflet/templates/leaflet/widget.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
<style type="text/css">{% block map_css %}
55
{% if map_width and map_height %}#{{ id_map }} { width: {{ map_width }}; height: {{ map_height }}; }{% endif %}
6-
{% if not display_raw %}#{{ id }} { display: none; }{% endif %}
6+
{% if not display_raw %}#{{ id_css }} { display: none; }{% endif %}
77
{% endblock map_css %}
88
</style>
99

1010
<script type="text/javascript">
1111
{% block vars %}var {{ module }} = {};
12-
{{ module }}.fieldid = '{{ id }}';
12+
{{ module }}.fieldid = '{{ id_css }}';
1313
{{ module }}.modifiable = {{ modifiable|yesno:"true,false" }};
1414
{{ module }}.geom_type = '{{ geom_type }}';
1515
{{ module }}.srid = {{ map_srid }};
@@ -42,4 +42,4 @@
4242
{% endif %}
4343

4444
{% if display_raw %}<p> Geometry:</p>{% endif %}
45-
<textarea id="{{ id }}" class="required" cols="150" rows="10" name="{{ name }}">{{ serialized }}</textarea>
45+
<textarea id="{{ id_css }}" class="required" cols="150" rows="10" name="{{ name }}">{{ serialized }}</textarea>

0 commit comments

Comments
 (0)