Forum Academy Marketplace Showcase Pricing Features

[SOLVED] Hide state/zip/country of an address

Hey everyone.

Is there a way to hide the state/zip/country when I display an address in a dynamic field? All my users are local, so there is no need for this extra info.

Sorry if this question is vey basic and i just missed something obvious. Thanks in advance!

You should be able to extract the component you need from the address. https://bubble.io/reference#Data.Messages.geographic_address

Hey Scott, thanks for the help.

I played around with :extract, and it seems that the feature would be helpful if I wanted, say, just the city name extracted from the address and nothing else.

However, i’m having to jump through hoops to get it to show me an address like “1234 Fake St Apt. 3, Dallas, Texas”. “St” is extracted as “Street” and I can’t get it to dynamically show if it’s “Apt.” or “Suite” or “#”, etc.

It would be useful to have a feature like inverse-truncate where I can eliminate the last n characters from a string. But seeing that I’m apparently the first person to ask this on the forum, there doesn’t seem to be a big demand for it. I may have to just deal with long addresses for the time being.

To truncate a string, use the following: https://bubble.io/reference#Data.Messages.text.truncated_right.

Truncate from end seems to give you only a certain number of characters, but starting from the end. So, in this case, it would only give me state, zip, and country, which is exactly what i DON’T want. :sweat:

Oh sorry, try “truncate to…” instead. You’ll need to determine the string length that you want to maintain, which is found by the string’s number of characters and subtracting n.

Ok Scott, I used your idea of taking the string’s :number of characters and subtracting n. However, the editor wouldn’t let me just do something like:

Current Contact’s>Address’s>Formatted Address>truncated to>Current Contact’s> Address’s>Formatted Address’>Number of characters> -15

(The 15 above is the sum of the characters in the address zip, state, and country, including spaces and commas).

So I had to come up with a workaround. It worked, but it wasn’t pretty. Here it is:

I made a new field in my Contact thing called “Address String Length”. Whenever a new Contact is created and an address is inputted and saved, the field “Address String Length” will be automatically populated with Current Contact’s> Address’s>Formatted Address>Number of characters> -15

Elsewhere, in the field where i want to display a truncated address, I dynamically set the contents of that field to Current Contact’s>Address’s>Formatted Address>truncated to>Current Contact’s>Address String Length

It works.

So, essentially, what I’m doing is taking the number of characters in the address, subtracting 15 (which is the number of characters that I want to eliminate from the end of the address) and saving that amount to the database as a number in a field of the relevant thing. Then I use that number as the value of the number of characters used to truncate the address.

Geez this is hard to explain. I think it’s solved. But if anybody ever reads this in the future and comes up with a better workaround, I’m all ears!

Thanks for your help, Scott.

1 Like

If you want an easier way to remove specific parts of a string, try the :find & replace regular expression.

For example, could have the pattern to be just the part you don’t want, using dynamic data, and the replacement empty.

Can play with expressions here…

1 Like

Hey, thanks for that new perspective on the problem. I actually decided to go with your way and using find and replace to remove the zip code and the “, USA” at the end of my addresses.

I don’t regret all of the tinkering I did because I learned some new things. But, per usual, there was an easier way. :grin: Thanks @mishav

1 Like