web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Switch text content of...
Power Apps
Answered

Switch text content of 2 textinput boxes around

(0) ShareShare
ReportReport
Posted on by

Hi guys, I am new to Power Apps.

 

I am asking users to enter text in 2 fields. I am looking for a function that should work for an icon (that looks like a switch).
I need a function that switches the text from box 1 to box 2 and the other way around. 

 

so:

1. enter text of textfield 1

2. enter text of textfield 2

3. click the switch icon

4. the text of textfield 1 is now in textfield 2 & the text of textfield 2 is now in textfield 1

 

Can anyone help me here?

Much appreciated!

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Jonask94 

    Set the Default of your first TextInput to lclText1 and the second Default to lclText2.

    Then set the OnSelect action of your Icon to:

    With({_or:TextInput1.Text},
     UpdateContext({lclText1: TextInput2.Text, lclText2: _or})
    )

     

    I hope this is helpful for you.

  • JK94X Profile Picture
    on at

    @RandyHayes 
    thanks for your input, however, how do I set the Default of my first TextInput to lclText1? 
    Set(lclText1,true)
    under default tab of my textbox?

    Thanks!

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Jonask94 

    I'm not following why you would want to set that to true.

    You wanted the ability to swap two textinput control values.  What I provided is all you need.

     

    Click on the Textinput control and then go to the Default property of it and put in lclText1

    Then do the same for the second textinput and set it to lclText2

    Then on the OnSelect of your "swap" icon, set the formula to:

    With({_or:TextInput1.Text},
     UpdateContext({lclText1: TextInput2.Text, lclText2: _or})
    )

    Replace the TextInput1 and TextInput2 references in the above to be the names of your textinput controls.

  • JK94X Profile Picture
    on at

    Hi @RandyHayes perfect, I didn't know you could simply set a variable in Default 🙂
    Happy new year

  • JK94X Profile Picture
    on at

    Hi @RandyHayes ,

    I have a new challenge since I want to add default values from a SP list in those 2 labels (so that they are prefilled, when coming on that screen), so I cant use the lclText1 & lclText2 anymore, right?

    On the on-select of the switch-icon I've put:

     

     

    With({_or: LookUp(Drivers;User().email=DriversEmail;D_Hometown.Value)};
     UpdateContext({lclText1: "Uzwil"; lclText2: _or})
    )

     

     

    With Drivers being my list and Hometown being the column in that list
    Uzwil is the final city (thats static) and therefore hard-coded.

     

    Jonask94_0-1641820447219.png

    As you can see I am getting an error, can you help me here once again?
    Generally your solution worked before:

    With({_or:txCityOfRouteStart.text)};
    UpdateContext({lclText1:txcityofrouteend.start;lclText2:_or}))


    Thanks!

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Jonask94 

    What error are you getting??

    The only thing I see wrong is that you have misspelled Email.  It should be User().Email, not User().email.

  • JK94X Profile Picture
    on at

    @RandyHayes 
    it says there are wrong arguments in the lookUp function.
    Ive tried with a capital E but it didnt solve it

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Jonask94 

    How is DriverEmail defined in your list?  Text, Person, etc?

  • JK94X Profile Picture
    on at

    @RandyHayes 

    Just as single line of text

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Jonask94 

    So, in the formula with the error, first - what is the error that it is stating?  Hover over the formula where there are any red underlines and see what the error is.  If there is a part that has a thicker red underline, then that is where the problem is...hover over that and let me know what the error message is.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 189 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 139

Last 30 days Overall leaderboard