Map not Loading on the template
Closed this issue · 10 comments
Map doesn't load on the form as expected. I have tried this with the sample map in the app but it is working fine. Could there be any special requirement needed when using form wizard? I am trying to load the map on a form wizard, but I am not sure if that is the problem. Console gives me this as an error:
Uncaught TypeError: Cannot read property 'value' of null at Object.getExistingLocation (google-maps-admin.js:92) at Object.initialize (google-maps-admin.js:41) at HTMLDocument.<anonymous> (google-maps-admin.js:165) at j (jquery.min.js:2) at k (jquery.min.js:2)
I also noticed that another jquery.js is loaded, which is of lower version 3.1.0
as compared to the jquery
loaded that is used in the project which is v3.2.1
Hello @madisona, sorry for taking long to respond to your response. After much digging, I realized that in the django-form-wizard, the form fields ids are named as id_{form_name}-address and id_{form_name}-geolocation. This breaks the google-maps-admin.js file since it is expecting the id in the form of id_address and id_geolocation. I changed this in the .js file to reflect the form field names and it worked. Problem is, now, it breaks other parts that I am using the google maps widget. Is there a way to fix this?
hi @japhethmutai I'm not sure of a great way to make the field id a variable you could specify and be able to pass that to an external js file. I'd love to know if you come across a solution for it, as it would be helpful to allow someone to specify the field id's they wanted.
Same issue here
The script expects you've named your fields exactly like the example. The stack trace leads me to believe your geocode field may not have an id of id_geolocation
.
The script expects you've named your fields exactly like the example. The stack trace leads me to believe your geocode field may not have an id of
id_geolocation
.
Oh, thanks for your reply. So there is no way to have 2 geolocation in the same django model?
Hi @iryna-horbachova - that's right, you wouldn't be able to have multiples on the same model without modification.
Similar happens if geolocation
field made read-only (as recommended in the description):
@register(Store)
class StoreAdmin(ModelAdmin):
list_display = ('name', 'address', 'geolocation')
readonly_fields = ('geolocation',)
jquery.js:4046 jQuery.Deferred exception: Cannot read property 'value' of null TypeError: Cannot read property 'value' of null
at Object.getExistingLocation (http://127.0.0.1:8001/static/django_google_maps/js/google-maps-admin.js:105:69)
at Object.initialize (http://127.0.0.1:8001/static/django_google_maps/js/google-maps-admin.js:41:41)
at HTMLDocument.<anonymous> (http://127.0.0.1:8001/static/django_google_maps/js/google-maps-admin.js:178:15)
at mightThrow (http://127.0.0.1:8001/static/admin/js/vendor/jquery/jquery.js:3762:29)
at process (http://127.0.0.1:8001/static/admin/js/vendor/jquery/jquery.js:3830:12) undefined
jQuery.Deferred.exceptionHook @ jquery.js:4046
jquery.js:4055 Uncaught TypeError: Cannot read property 'value' of null
at Object.getExistingLocation (google-maps-admin.js:105)
at Object.initialize (google-maps-admin.js:41)
at HTMLDocument.<anonymous> (google-maps-admin.js:178)
at mightThrow (jquery.js:3762)
at process (jquery.js:3830)
Django 3.1.7
@dmugtasimov - the sample app admin.py shows how to make the geolocation field readonly and have it still work appropriately: https://github.com/madisona/django-google-maps/blob/master/sample/admin.py