Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaflet widget is not rendered automatically for forms.Forms #108

Open
faaizajaz opened this issue Aug 8, 2020 · 4 comments
Open

Leaflet widget is not rendered automatically for forms.Forms #108

faaizajaz opened this issue Aug 8, 2020 · 4 comments

Comments

@faaizajaz
Copy link

faaizajaz commented Aug 8, 2020

Hi, and thanks for this fantastic project (and django-leaflet).

Using the leaflet widget on modelForms (where the model has a corresponding geom field, e.g. PointField()) works as expected, however when using forms.Form the behavior is not consistent.

The docs say that form widgets are rendered with Leaflet automatically if django-leaflet is available, but this does not seem to be the case.

Taking a simple example:

class SampleForm(forms.Form): location = djgeojson.fields.PointField()

From the docs, we expect that when this form is rendered, there will be a leaflet widget for the location field, which does not seem to work.

@Gagaro
Copy link
Member

Gagaro commented Aug 24, 2020

GeoJSONField is the model fields. You must use GeoJSONFormField in a form.

class SampleForm(forms.Form):
    location = djgeojson.fields.GeoJSONFormField(geom_type='POINT')

@faaizajaz
Copy link
Author

Thanks Gagaro, this works and looking at the djgeojson/fields.py I can see why. It's not immediately obvious to me why this is not required when using forms.ModelForm. In that case, the PointField is automatically rendered as a leaflet widget, which is the behavior expected from reading the docs. I guess this has something to do with forms.ModelForm itself?

Perhaps it would be useful to update the documentation for both the ModelForm and Form use cases?

@Gagaro
Copy link
Member

Gagaro commented Aug 31, 2020

I'm not sure why it would work in some cases.

Feel free to update the docs and do a PR or point where in the doc it is, I'll try to update it when I find some time.

@faaizajaz
Copy link
Author

Sure, I will take some time this week to test and update myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants