You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These snippets below are what I had after a workshop I held at Visuality last year. They won't deliver the finisehd result, but it's a great starting point.
This will give you a custom field that you can add to your app and will search mapbox.
Approach
The user will start to type some text in the input and when they select an option from the dropdown they will get a payload at their disposal from mapbox.
# Let's imagine that mapbox returns this payload for the query# *I don't have the response in front of me{full_address: "55 George Washington st., New York, USA",street_address: "55 George Washington st.",street_number: "55",city: "New York",state: "NY",country: "USA",}
API
# when the form gets submitted it will populate the `address` column with the full address received from mapbox and all the parsed fields onto the record.# Nothing happens when the form gets submittedfield:address,as: :mapbox_address# All the fields from the response are passed to the recordfield:address,as: :mapbox_address,map: :all# only the fields in `map` are being passed to the recordfield:address,as: :mapbox_address,map: [:full_address,:street]# the fields from `map` are passed to the record with the key being overwritten by `custom_mapping`field:address,as: :mapbox_address,map: [:street_address,:city,:country],custom_mapping: {street_address: :street,city: :town}# give the user access to the `record` and `respomse` and they can choose what happensfield:address,as: :mapbox_address,populate: ->{# maybe we can use `update_using` instead here?record.street=response[:street_address]}
If the record has an address column/property, let's display that in the UI, but let's think about a way to show the input only if the user wants it. We can talk about it.
Mapbox Field
These snippets below are what I had after a workshop I held at Visuality last year. They won't deliver the finisehd result, but it's a great starting point.
This will give you a custom field that you can add to your app and will search mapbox.
Approach
The user will start to type some text in the input and when they select an option from the dropdown they will get a payload at their disposal from mapbox.
API
If the record has an
address
column/property, let's display that in the UI, but let's think about a way to show the input only if the user wants it. We can talk about it.Snippets
The text was updated successfully, but these errors were encountered: