Tuesday, February 20, 2018

PowerApps: Change Color of the button on select event

Use Case: In a quiz app, you need to put three buttons and based on the value of the button, color should be change. It should look like:




Or:




So how you do this? First, you need to put three buttons. In the “OnSelect” event of the button, you need to write following code:
UpdateContext({M1Q1Btn1ColorFlag:!M1Q1Btn1ColorFlag, M1Q1Btn2ColorFlag:false, M1Q1Btn3ColorFlag:false, Q1Ans:Button3.Text})




In addition, the “Fill” property of the button you need to put:
If(M1Q1Btn1ColorFlag = true, RGBA(0, 255, 0, 1), RGBA(230, 230, 230, 1))




Similarly, you need to do for “No” button as follows -
OnSelect: UpdateContext({M1Q1Btn1ColorFlag:false, M1Q1Btn2ColorFlag:!M1Q1Btn2ColorFlag, M1Q1Btn3ColorFlag:false, Q1Ans:Button2.Text})
Fill: If(M1Q1Btn2ColorFlag = true, RGBA(255, 0, 0, 1), RGBA(230, 230, 230, 1))


After the placement of the Buttons, you can put one Label to keep the response from the user. Later you can hide this label and use it at the event of the Finish Button to send it to SharePoint list or Excel.

No comments:

Post a Comment