cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
audrieg
Level 10

Set Control Value/Text OnChange

Could we please have the ability to set a control value based on the change of another control?

 

Example:

 

TEXTBOX1: Enter your HR Code please....

TEXTBOX2: (a hidden text box controlling some IF/THEN statement elsewhere in the app)

 

TEXTBOX1: OnChange>> Set.TextBox2.Text = This.Text

 

I understand we use collections and context, but it would be nice to have the option to simply set a value too.

 

Thank you.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff murali
PowerApps Staff

Re: Set Control Value/Text OnChange

@CameronCaudill

 

PowerApps is driven by a declarative dataflow language. What this means is you tell control properties where to get their values and dataflow takes care of setting values. It's different from imperative languages where you tell objects to do something.

 

For instance.

 

If you want TextBox2 to have the same "Text" as TextBox1 i.e. whenever TextBox1's Text changes, change TextBox2's Text, you do the following:

1. Select TextBox2

2. Set it's Text property to TextBox1.Text.

 

Dataflow takes care of updating TextBox2.Text whenever TextBox1.Text changes.

 

Hope that clarifies things.

 

Thanks

Murali

View solution in original post

17 REPLIES 17
PowerApps Staff AndyPennell
PowerApps Staff

Re: Set Control Value/Text OnChange

Can't you do:

 

TEXTBOX2: Text=If(TextBox1.Text="1","a","b")

 

When Textbox1.Text changes, so will Textbox2.Text.

audrieg
Level 10

Re: Set Control Value/Text OnChange

Didn't work for me (see screen shot below). In that screen shot I tried your statement as a button click, and the onchange of the trigger text box. Am I missing something?

 

I understand your expression to mean:

IF Textbox1.Text is equal to 1, then make Textbox2.Text equal to "a"

ELSE (not equal to 1) make Textbox2.text be equal to "b"

 

I'm really looking for something that is not an "IF" statement - it's a SET statement (irrelevant of any condition) meaning - SET that.value to this.value whenever this.value changes. It makes it very easy to integrate business rules into forms.

 

Here is my effort at your suggestion - I annotated it so you'd know what I did:

 

In my last try: I had to modify your expression to include the target input box. In that case, the button worked, and the default works - but it won't change to "a" when the Trigger input box changes.

 

I have uploaded the file to here:

https://1drv.ms/u/s!ArGMAcQsnkwmcsnhBpQbyF0SsYo

Repro: change Trigger to 1 - the default value should now change to a. (I think PowerApps people have a different definition of the word "default" than I do. LOL

IMO "Default" means the very first value, that is editable in any way you can edit it. - But PowerApps seems to be very "STICKY" on default values for some reason. (FYI: This is a true scenario to SharePoint Apps because all editform fields must use Parent.Default values....so I need to be able to overwrite the default in some cases.)

 

sample.PNG

 

 

 

 

 

 

 

Highlighted
SergioGiusti
Level: Powered On

Re: Set Control Value/Text OnChange

Hi did you get anywhere with this?

 

I have the same query, i have a control getting a dropdown choice list from a sharepoint list, when its value is selected id like to set another controls value dependent on what was chosen.

 

i.e.

 

SharePoint list 1

Column 1 - Column 2

ABC           DEF

 

SharePoint list 2 (my PowerApp)

Column 1 is a lookup to Column 1 in list 1

Column 2 is a text field

 

If column 1 is selected, if like it to input the value from Column 2 in list 1 into Column 2 in list 2

 

Hopefully that makes sense.

 

Thanks

audrieg
Level 10

Re: Set Control Value/Text OnChange

Yes, I got it to working exactly the way I wanted it to using the UpdateContext function. Just remember that it is contextual for that screen only.

 

UpdateContext details:

https://powerapps.microsoft.com/en-us/tutorials/function-updatecontext/

PowerApps Staff murali
PowerApps Staff

Re: Set Control Value/Text OnChange

@CameronCaudill

 

PowerApps is driven by a declarative dataflow language. What this means is you tell control properties where to get their values and dataflow takes care of setting values. It's different from imperative languages where you tell objects to do something.

 

For instance.

 

If you want TextBox2 to have the same "Text" as TextBox1 i.e. whenever TextBox1's Text changes, change TextBox2's Text, you do the following:

1. Select TextBox2

2. Set it's Text property to TextBox1.Text.

 

Dataflow takes care of updating TextBox2.Text whenever TextBox1.Text changes.

 

Hope that clarifies things.

 

Thanks

Murali

View solution in original post

audrieg
Level 10

Re: Set Control Value/Text OnChange

Yes, I've been doing that and honestly, I'm getting used to the approach more and more each day. 🙂

 

I was wondering if you have any recommendations on a similar topic: Input Mask approach.

 

I want to control the format of what my customers can enter into the text box. Do you have any ideas on that point that I can share with others? I've got a couple of workarounds but I'd love your ideas as a SME.

 

Thank you again!

Audrie

 

 

drbsoftware
Level: Power Up

Re: Set Control Value/Text OnChange

Suppose I have 2 text boxes, Country and Currency.

When I set Country, I want a default Currency to be set, provided no Currency has been set.

But I want the User to be able to override the Currency setting.

Is this possible with the rule engine?  If so, how?

roknron
Level: Powered On

Re: Set Control Value/Text OnChange

The onSelect property of the button is not setting the value of TxtTrigger.Text.  Just change the onSelect of the button to TxtTrigger.Text = "1", then test the value of TxtTrigger.Text in the onChange property of the next box.  I'm not certain that the onChange event will be fired if you set the value with another control.  The defaut value can be anything you like in your third textbox, but, for you example to work you need to set the Text proprety of the third textbox to TxtReveived.Text.  For your last TxtRecieved.Text value should be reflected as a. 

sscarcella
Level 8

Re: Set Control Value/Text OnChange

I have 2 choice fields in a SharePoint list that are Yes/No fields.  I want field 2 to have No selected if field 1 is Yes.  I cannot figure out how to do this with updatecontext.  Can you explain what you did.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 308 members 5,736 guests
Please welcome our newest community members: