Setting textbox text value on button click

Farheen Shafqat picture Farheen Shafqat · Dec 6, 2019 · Viewed 7.9k times · Source

I have a from in PowerApps with labels and textboxes. By default textboxes are empty. There is a Button named "Copy last row" when use will click on this button some sample values should be displayed in textboxes.

I checked on internet and the following solution was suggested by PowerApp support.

You need to set the text box' text property to this:

 If(HasBeenPressed, "Hello", "GoodBye")  

You also need to set the button's onselect property to this:

UpdateContext({HasBeenPressed: true})

or for more fun,

UpdateContext({HasBeenPressed: !HasBeenPressed})

But when I go to the properties of my textbox there is no such property like 'TEXT'.

Answer

Bruno Ferreira picture Bruno Ferreira · Dec 6, 2019

What do you mean by textbox? a label or a text-input?

Anyways, Label has a text property: enter image description here

Text-input has a default property enter image description here

I'm afraid u can't change the text directly. What u can do is create a context variable in the property "OnVisible" of your screen and give the default text you want your labels to have in the first place, or leave the variable in blank since you want them to have no text:

On visible context variable enter image description here

Then, set the text property of your label to be the value inside the variable enter image description here

Or the default property of your text-input enter image description here

Last but not least, set the OnSelect property of your button to change the value of your variable: enter image description here

This is the result: enter image description here

Hope this helps!