String concatenation for state values?

@potentialthings, do you know if this should work with state values of type text as well? The usual dynamic data menu appears, but I can’t seem to enter any string constants. :confused:

Ooo, I’ve never tried it with state values. Good question.

No it doesn’t work with states. :frowning:

YES! I go it. Follow this simple 12 step process. LOL

I wanted to share this since I had to go through “H E double hockey sticks” to get there. (To the Bubble team, please make this easier and you will reap the benefits!)

In my case I wanted to concatenate only two components of full address field into a custom state. Do this.

  1. Create an input field (that you will later delete only used for this operation)
  2. In this input field make sure the CONTENT FORMAT is set to TEXT
  3. Enter in the INITIAL CONTENT box your first part followed by spacebar then enter your second part spacebar so forth
  4. In my case it was something like AddressField Extract City (space) AddresField Extract County
  5. TRICKY PART: Now change the CONTENT FORMAT of this temporary input field to ADDRESS
  6. Right click in the INITIAL CONTENT and select COPY
  7. Go to your WORKFLOW and select SET STATE
  8. Create new CREATE NEW CUSTOM STATE eg. STATE NAME: MyConcatPartAddress
  9. Make it STATE TYPE: ADDRESS
  10. Right-click in the VALUE box and select PASTE
  11. Test your value of the state (eg. a text box) and you may now delete the input you created for this operation

Consider this as “Paying It Forward” in appreciation to others that have helped me along the way specially in my early stages more than a year ago. Specially @NigelG @romanmg

5 Likes

Yep, this turned out to be pretty handy!

1 Like

Nice work @mente12 - really appreciate the solution. But it’s absurd that we can’t do this in one natural step… instead of in 12 easy steps. Here I’ve been banging my head for an hour trying worthless workarounds until I came across this post. What’s the best way to get the bubble team to fix this?

2 Likes

There’s a method I’ve been using which is just one step. Basically, it relies on the ‘find-and-replace’ function. Simply set the first text value in the custom state then apply a find-and-replace to the text. In this case, the text that you find is the same one in the custom state. The replace function allows you to mix dynamic and static data so you can then replace it with whatever you want.

1 Like

Or I’ve got another equally simple way that I use all over my app… make the value of the state “current date/time is not empty:formatted as text”. This will obviously always equate to “yes”, and in the “yes” box you get the full dynamic value editing area where you can concatenate to your heart’s desire…
(Credit to @keith for passing on the idea!)

9 Likes

Thanks for mentioning that, @antony — I was gonna post but couldn’t quickly find that reply to you where I explained that (you may wanna link to that if you’ve got it handy).

BTW, to others interested: While it’s sometimes frustrating, this behavior is not a bug. There’s an expression field for “any type of value” and there’s a text-specific expression field specifically for texts.

Internally, we can only display the text-specific field when we know the input value can ONLY be a text. (@antony, you might have run across this by now in your explorations on the plug-in editor… it’s the “Long Text” option in the field editor if I’m not mistaken.)

Hey Keith, it’s a pleasure… I’ve edited the post to credit you with the idea! :slight_smile:

1 Like

Perhaps you can elaborate with pictures? What type are you setting the state to?

This is a point of real frustration for me. All I want to do is display a marker on a google map and it seems like I have to concatenate values (namely street, city, state…) as the Marker Address. Despite about 30 variations I’ve tried for injecting an address into the Marker Address field for the map widget, I just can’t seem to get it to display the address. I’ve tried setting the value to a custom state (of type TEXT, Geographic Address, Text formatted as an address) but that doesn’t work. I’ve tried @mente12’s solution but that also didn’t work (resulted in very strange behaviors in the editor where my dynamic address would resolve to some random address… almost like geocoding was actively… well… geocoding). Below I even seem to have the right information for the current marker’s address but that doesn’t work either… what do I do?

Hey, @zelus_pudding… is your app on a yourappname.bubbleapps.io domain, or on your own custom domain?
If you’re on the latter, then there appears to be a bit of a complexity in getting the mappings stuff to work… see below for the (currently partial) details!
Best wishes,
Antony.

@zelus_pudding, unless I’m misunderstanding, you might want to try a Search Box input element and set it to Geographic places. It might simplify things considerably if you’re trying to enable users to specify a location and then display it on a Gmap.

Excellent suggestion @antony - that’s really good to know about though it actually wasn’t an issue I had run into. I couldn’t implement @sudsy’s suggestion for various reasons but fortunately I figured out how to force GMaps to render my address stored as a state from a concatenation of strings. It’s so round about my head’s spinning:

  1. create a custom state of type TEXT

  2. DO @antony’s / @keith’s hack to (in a workflow) set the value of the state to “current date/time is not empty:formatted as text”:
    image

  3. Concatenate the strings of interest in the formatted text dialogue that the above step opens:
    image

  4. Create an invisible input who’s initial content is set to the custom state’s value and make sure to set it’s type to ADDRESS.

  5. Finally, set the MARKER ADDRESS of the map element to the value of the invisible input element from step 4.

Phew.

Thanks all for the help

Hey @zelus_pudding, that’s great you’ve been able to work through the solution. These challenges seem like such a mountain to climb at the time, and the relief it so great when you reach the summit! :slight_smile:

1 Like

Nice @zelus_pudding

You could avoid using an invisible input field by doing this: …

… You could use another Set State (Geographical Address) call it say “geo_address” and who’s value will come from State “kitchen_address_full” (text) value. Then assign the map marker to the Geographical Address state; “geo_address”.

Rick
Developer

1 Like

I had a really difficult time with this, not because the community didn’t provide great ideas on how to make the process of translating address to geolocations, but because the whole google console and API thing is a bit hard for me as a non-technical person to understand, which APIs I need etc.

I kept getting this error message

Finally I went into the google console and enabled more APIs ( the ones that cost money per 1,000 requests )

After enabling the Geocoding and Geolocation API it works and I am able to take the text fields and translate them to geographic addresses.

I believe this is because I am on a custom domain.

I am a bit concerned about seeing the Geocoding API showing 28 requests as I have only made one request after enabling.

Does anybody have any insights / tips on how to properly manage the number of requests so that google doesn’t end up charging me huge sums of money?

So I got things working and was successful at setting up a way to translate the text values of street address, city, state and zip code in geographic locations. I was also able to set up an API workflow to do it for a list of 5,000 different companies.

I used a method suggested on here with “current date/time is not empty”

First I have the page with a repeating group containing the business listings which have the addresses listed as text fields.

Then I set up this API workflow on a list

If you are not familiar with API workflows, as I was not, watch this video by @romanmg

Something to be aware of is settings in google console…At first it didn’t work for me because I didn’t have the Geolocation API set to restricted on my server API key

In the credentials area
12%20PM

Go to your server API Key settings and choose from the drop down list the google APIs to restrict (which actually means allow to be used - thanks for making it counterintuitive google)

Now, of course I couldn’t run the entire 5000 entries at once as the app times out often, but it is better than trying to do it all by pressing an individual button 5000 times.