You don't need several text elements to display different texts under different conditions. You can use conditional statements to change the text. This will make your app simpler to organize and manage.
Creating the conditional statements
Let's say you have a dropdown where I can select a product. You want a text element which tells you whether the product is 'For Sale' or not. But, the status of the product is stored in a Yes/No field type, so you cannot display the product status using dynamic data.
How you can do it is to create two conditional statements. One to show a text if the 'For Sale' field is Yes and another if it is No.
- You begin by creating a text element and styling it how you want.
- You then add 2 conditional statements to the text.
- If the Dropdown value's For Sale is "yes" > Select a property to change when true > Text. Now you can enter whatever text you want to be displayed.
- If the value is "no", you can show a different value.
And this is a generic example. You can also change the font, color, alignment and a host of different properties of the text element depending on the conditions.
Let's take another example, let's say you want to show a text based on the custom state value. More on custom states and their use cases. We can create a simple toggle element to change the custom state value. Then we can use the custom state's value to show text based on the current value of the custom state.
- I created a custom state at the page level called "Active". The value of the custom state depends upon the toggle element.
- If the toggle is checked, the value is "Yes", else it is "No".
- I created another text element and put conditions similar to the ones in the earlier example.
The main takeaway is that just like the other features of Bubble, the text element is also powerful and can be customized for our needs. The only limiting factor is our creativity.