cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GrischkePro
Advocate III
Advocate III

Toggle switch with another button OnSelect (on save) (SharePoint list)

How can I toggle a switch (or tick a checkbox) with another button?

 

I need a hidden Toggle (Yes/No), by default it's OFF. I want another button, that will toggle the switch to ON and then submits the form.

 

How can I achieve this?

 

Many thanks

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@GrischkePro 

One quick way to do this is the use of a variable.

In your Button OnSelect action use a formula such as this:

   Set(setToggle, true)

 

Then on your Default property of the Toggle control, set this formula:

   setToggle

 

If you are using the toggle to then perform an action in the "OnCheck" action of the control, then do your formula, and then at the end, place a Set(setToggle, false) to reset the toggle back so that it can be "called" again.

 

This is a very useful pattern to do with toggle controls.  HOWEVER, there is one word of warning...

If you put your toggle control on another screen, you need to at least reference the Toggle Control on the screen where your button is.  You can do that simply enough with a non-visible label with the text property set to yourToggleName.Value

This will work perfectly from any screen (as long as you have a referencing "dummy label").

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

@GrischkePro 

One quick way to do this is the use of a variable.

In your Button OnSelect action use a formula such as this:

   Set(setToggle, true)

 

Then on your Default property of the Toggle control, set this formula:

   setToggle

 

If you are using the toggle to then perform an action in the "OnCheck" action of the control, then do your formula, and then at the end, place a Set(setToggle, false) to reset the toggle back so that it can be "called" again.

 

This is a very useful pattern to do with toggle controls.  HOWEVER, there is one word of warning...

If you put your toggle control on another screen, you need to at least reference the Toggle Control on the screen where your button is.  You can do that simply enough with a non-visible label with the text property set to yourToggleName.Value

This will work perfectly from any screen (as long as you have a referencing "dummy label").

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

@RandyHayes 

 

This is brilliant! I was almost there, just didn't know where to apply the variable 🙂

 

FYI, I needed to toggle it "on save" without the user knowing about it, so that Flow knows what to do next 😉

 

Thank you very much! Smiley Very Happy

Thanks this is very helpful

Hi Randy,

 

This was very useful information about references to off-screen controls.

 

I was using the OnCheck property of a toggle on Screen1 to drive some behaviour. The Default property of the toggle Or'd together the outputs of two components, one on Screen1 and the other on Screen2.

 

In PowerApps Studio, activating the component on Screen2 would trigger the OnCheck behaviour as expected. However doing the same when launching the App from its weblink, or embedding in Teams would not trigger the toggle's OnCheck behaviour.

 

Per your suggestion, adding a label to Screen2 which referenced the toggle on Screen1 resolved the issue.

 

Do you have a link to any documentation which describes how PowerApp handles offscreen controls? I haven't been able to find any myself.

 

Thanks,

 

Dan.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,616)