Skip to content

Commit

Permalink
Merge pull request #126 from CulturePlex/fix/extra_chars_field_name
Browse files Browse the repository at this point in the history
Added slugged strings for accepting multi-word field name (fixes #123)
  • Loading branch information
leplatrem committed Nov 10, 2015
2 parents 29a9323 + a664cc9 commit bf1b50d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions leaflet/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

from django import forms
from django.template.defaultfilters import slugify
try:
from django.contrib.gis.forms.widgets import BaseGeometryWidget
except ImportError:
Expand Down Expand Up @@ -46,8 +47,10 @@ def render(self, name, value, attrs=None):
if self.geom_type == 'GEOMETRY':
attrs['geom_type'] = 'Geometry'

map_id = attrs.get('id', name).replace('-', '_') # JS-safe
attrs.update(id_map=map_id + '_map',
map_id = slugify(attrs.get('id', name)).replace('-', '_') # JS-safe
attrs.update(id=map_id,
module='geodjango_%s' % map_id,
id_map=map_id + '_map',
id_map_callback=map_id + '_map_callback',
modifiable=self.modifiable,
target_map=attrs.get('target_map', getattr(self, 'target_map', None)),
Expand Down

0 comments on commit bf1b50d

Please sign in to comment.