Forum Documentation Showcase Pricing Learn more

String concatenation for state values?


#1

@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:


#2

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


#3

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


#4

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

Yep, this turned out to be pretty handy!


#6

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?


#7

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.


#8

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

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.)


#10

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


#12

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


#14

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?


#15

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.


#16

@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.


#17

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 @shot’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


#18

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:


#19

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