Forum Academy Marketplace Showcase Pricing Features

[SOLVED] Change button text based on button's clicked state

When I click the button ‘Follow’, I want the text to be replaced with new text that says ‘Following!’. As it is now, when the Follow button is pressed, the new text on the button appears briefly, then the button reverts back to the old text.

Here is the link in the public editor. Go the Preview mode to see the button’s behaviour:

https://bubble.io/page?type=page&name=follow-button&id=forumapp3&tab=tabs-1

Here is the conditional logic when the button ‘Follow’ is pressed (you can see this in the editor as well):

How can I get the new text ‘Following!’ to remain after the button is pressed?

Thanks,
RG

You have to store this state as a field on a “Thing”. So the button triggers a workflow that sets the state. In the conditional tab, you create a condition to check if this field is set to true or false.

1 Like

Hey @R.Galbraith :slight_smile: If you’re trying to create an app where users can follow-unfollow others, you would want to store who the User is following as a field.

To set this up, you could add a new field within the User Data Type called “Follow List” (Type: Users, List: Yes).

So if a User navigated to that page and clicked on that button to Follow another User, the event in workflow would be:

"When Button Follow is clicked and when Current User’s Follow List doesn’t contain Current Cell’s User --> Make Changes to a Thing --> Current User --> Field to Change: Follow List ‘add Current Cell’s User’.

Back in the UI Editor, on that button you could create a conditional statement which said:

“When Current User’s Follow List contains Current Cell’s User”
Text = Following! (or… have it be ‘Unfollow’)

Then have another event in the workflow which said:

"When Button Follow is clicked and when Current User’s Follow List contains Current Cell’s User --> Make Changes to a Thing --> Current User --> Field to Change: Follow List ‘remove Current Cell’s User’.

3 Likes

@fayewatson, Thank you!!! Your wonderful reply resolved my issue and as a bonus helped clean up some of my DB logic. I am grateful :slight_smile:

1 Like

@soeren, Thank you for your reply.

So happy to hear @R.Galbraith!! :blush: My pleasure!