Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Google Geocoding in Backend

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1084 Views
  • eddieconnecti
    Avatar
    Community Member
    26 Posts

    Google Geocoding in Backend Link to this post

    Hello! I am asking myself if is possible to create my own formfields? Problem is: I created a class called "Location" which extends ModelAdmin. There are two fields Latitude and Longitude. Now I would like to show a map below the form, where I can move the marker to a specific position. Aftere that the coordinates can be copied into langitude and longitude textfield.
    I first started doing this with my own javascript file, using jquery to detect the form and adding the map and functions. But this failed, since it gets no document.ready event because the model is loaded after the page is loaded. Maybe there is an event I can use too, but it is not perfect. I better would use my own formfield, like so:

    new GeocodingField( [mapname], [name of Latitude field in form], [name of Longitude field in form], [google api key] )

    I had a look at the label field, since this field does not have any database action. But I need a better understanding of whats going on inside the class and I need to know, if this is a recommended way to solve this problem?

    Maybe there is a better way and I don´t see it at the moment? Thanks for your help!

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Google Geocoding in Backend Link to this post

    Hello! I am asking myself if is possible to create my own formfields?

    Yes you're free to create your own formfields. The main function on a FormField subclass that you need to have is a Field(). This returns the HTML of the form field. An example of kinda what you want with the map is a module - googlemapselectionfield which is a form field which allows you to select a point. http://open.silverstripe.org/browser/modules/googlemapselectionfield/trunk/code might be useful

  • eddieconnecti
    Avatar
    Community Member
    26 Posts

    Re: Google Geocoding in Backend Link to this post

    Wow! Thtas just great! I will try it and give you feedback.

    Thanks you so much for your help Willr!

    1084 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.