django-leaflet
django-leaflet copied to clipboard
Geom field value should not be modified when deserializing its content
@Zhigal you change the value of the input field when deserializing:
this.formfield.value = JSON.stringify(JSON.parse(value));
This is a problem for me. My code does not work anymore with this change. Could you explain the rationale behind your fix ? Why de-re-serialize, why modify de DOM ?
Are you OK with this PR ?
Relevant PRs:
https://github.com/makinacorpus/django-leaflet/pull/291 https://github.com/makinacorpus/django-leaflet/pull/294
@gutard, I'm really sorry for breaking your code. But the rationale behind those changes is that this allows to keep input field syncronized with the geometry on a map with the set number of decimal places. I need this because varying precision was adding unpredictable error in my app. Your changes do not make any sence to me since input field will have varying presicion and unpredictable number of decimal places.
We may do something like this:
if (value === 0) {
var _value = JSON.stringify(JSON.parse(value));
return L.GeoJSON.geometryToLayer(JSON.parse(_value));
} else {
this.formfield.value = JSON.stringify(JSON.parse(value));
return L.GeoJSON.geometryToLayer(JSON.parse(value));
}