Hi,
Is it possible to change the text color, or shape color when user click a button?
Hi,
Is it possible to change the text color, or shape color when user click a button?
Yes, you can using custom states. I can show you how to do this if youâd like; I would just need the link to your appâs editor and what color youâd like the button to change to on click.
Here is the link:
Ok great in your app I created a custom state on Shape A called Color (Type: Text, List: No) described below. The event in the workflow could be set up like this:
When âChange Colorâ Button is clicked â Element Actions â Set State â Element: Shape A, Custom State: create a new custom stateâŚ
And set the event workflow actions up in this way:
Here weâre telling Bubble that when the Change Color Button is clicked, and Shape Aâs Color value is âGreyâ, set the value to âBlueâ.
Then I created another workflow when the Change Color Button is clicked and Shape Aâs Color value is âBlueâ, set the value to âGreenâ:
And when the Change Color Button is clicked and Shape Aâs Color value is âGreenâ, set the value to âGreyâ.
After the workflows are set up, then Shape A needs this conditional formatting in order for Bubble to know which colors exactly should be changed, depending upon the value of the Color custom state:
The last workflow we need is just to set the Color state of Shape A to Grey when the page is loaded:
Awesome. Thank you very much for this tutorial. Works perfectly.
My pleasure!
Interesting! I now realize how useful states might be
Yes! They can save a lot of time and create a ton of possibilities
Hi. Iâm new on Bubbler and already learned the basics. But I still donât understand how to change the color of a button when it has been clicked.
I donât get the beginning with the creation of âShape Aâ. Can somebody help me please? All of you guys seem to figure it out. Thanks in advance.
Thanks Hikaru.
But how can the background colors change only when you click (not press) on the âSend buttonâ
I would like to change the colors of this button âAjouterâ
Can you show me step by step please? I created a blue âAddâ button, when the user click on it, the button changes color and become grey. Only after clicking on it (not hover).
If you dont want your button to change on hover, click remove condition.
Hi @ulrich_00132 Here is a step-by-step:
Preview:
Editor:
In this example, there is a blue âAddâ button:
In order to make sure the User only clicks the button one time, and the button turns grey after one click, we need to create and set a custom state (as @hikaru did) There are a few different ways to set up a custom state, but I find the easiest one is to click on the button element to open the property editor, and then select the âiâ icon in the top right corner to open the âElement Inspectorâ:
This Element Inspector will list all of the elementâs custom states, and any workflow events that involve the element. In order to setup our custom state, we can click âAdd a new custom stateâ:
Which brings up this popup:
Custom states are a bit confusing to explain, and sort of make more sense the more you set them up! Custom states can be used for many different reasons (e.g., keeping track of when a button has been clicked, temporarily storing a list of Products that a User has selected, temporarily storing a specific preference, and more). Unlike your appâs data which is stored âserver-sideâ, custom states are stored âlocallyâ for each User, meaning - once the User refreshes the page or changes pages, the custom states all get refreshed as well. In this example, since we only need to know whether the User has clicked a button, or if the User hasnât yet clicked the button, we can set up a âyes/noâ custom state called âClicked?â:
After saving that we can set the default value of the custom state to be ânoâ (or âfalseâ) since when the page is first loaded, the User has not yet clicked the button.
Because weâve set up this custom state, we can change it from ânoâ(false) to âyesâ (true) in a workflow when the Add button is clicked. To do this, we can set up a workflow:
âWhen Button Add is clicked, *only when Button Addâs âClicked?â custom state is noâ â Set the Button Addâs âClicked?â custom state to âyesâ. This makes sure that this workflow only occurs when the User is clicking the button for the first time:
Element Actions â Set State:
Set State action:
This workflow successfully changes the buttonâs custom state, but in order to change it to grey as well, we need to add a conditional which changes the buttonâs color to grey when its âClicked?â custom state value is âyesâ:
You can see it in action here!
And that should work! Feel free to let me know if I can clarify anything or if you have any questions!
@fayewatson & @hikaru : Thank you guys, you save my life
Just found this, and itâs SO helpful. Thank you so much for taking the time to lay this out so clearly and patiently. I really appreciate it.
Thank you so much, @SamUpstarters ! Itâs my pleasure! So glad it was helpful!
Hey fayewatson you still rock in 2021,
Thanks !
Hi guys, thank you all for this step-by-step guide ⌠i have one more question regarding the button state. If i understand correctly, this button color change is only session-based right? What would i need to do, to make this state write the change to the database?