cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
James141
New Member

Changing a component input property with a button

I'm trying to do something in a canvas app which I assumed was quite easy but obviously missing something here! 

 

I'm trying to change a components input property on a button click. For example changing a label that's in a component when someone clicks a button. I've tried this with both text inputs and boolean inputs. I've tried to simplify the example here, and I'll describe a text input.

 

1. I created a component called MainTitle, and added an input called "TitleDescription".

2. I put a label into the component and into a label I put MainTitle.TitleDescription

3. On an app screen I inserted the component, it showed up as MainTitle_1 

4. On app screen I selected the component, and in the property drop down I saw my TitleDescription, I set this to "Main Screen" and the label updated as expected.

5. I made a button, and in that button I tried to change the TitleDescription on click. I put in the code

       MainTitle_1.TitleDescription = "New title";

 

This is where it goes wrong compared to what I expected. Clicking the button has no impact on what is shown on screen, and checking the input TitleDescription it hasn't changed.

 

Could someone point me in the right direction please? Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
Adrian_Celis
Super User
Super User

Hi @James141 

You should use a variable to make it work.

1) In your button OnSelect property, set a variable, let's name it "varTitle":

UpdateContext({varTitle: "New Title"})

2)In your component TitleDescription property, use the variable.

varTitle

Once you click on the button, it will have "New Title" as the TitleDescription

 

View solution in original post

1 REPLY 1
Adrian_Celis
Super User
Super User

Hi @James141 

You should use a variable to make it work.

1) In your button OnSelect property, set a variable, let's name it "varTitle":

UpdateContext({varTitle: "New Title"})

2)In your component TitleDescription property, use the variable.

varTitle

Once you click on the button, it will have "New Title" as the TitleDescription

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,858)