cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Christy_Roach
Advocate II
Advocate II

Need to be able to toggle back and forth visibility of questions based on answer being yes or no.

I have a field that has a toggle yes/no option.  That field defaults to yes.  With the default of yes,  there are several questions following that default to showing.   If they toggle the answer to no, the questions go away (are not visible). All of this is working just fine.

 

I want them to be able to toggle back and forth and the questions show or don't show based on the toggle.  After the initial choice of "no" is made and the questions go away, you can't toggle back to bring the questions back.  There has to be a way to do that doesn't there?  Any help would be appreciated. 

 

Current settings:

On the OnUncheck variable, I have UpdateContext({cursel:false})

Then on all of the subsequent fields I have Visible = cursel

 

What do I need to change/add to get the toggle back and forth to work? Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Christy_Roach

 

I would suggest not setting the context variable during the onselect event of the toggle. Just access the value of the toggle directly.

 

If you use a toggle control, then you don't have to set a variable with the value as the toggle itself has a value of true or false. This can be referenced in the visible property of the other controls: Toggle1.Value. This will show the control if the Toggle is 'On' and hide it is it is 'Off'. If you want to show the control when the toggle is 'Off' and hide it when the toggle is 'On', you can use !Toggle.Value in the visible property of the controls.

 

 

View solution in original post

7 REPLIES 7
DavesTechTips
Super User
Super User

Hi @Christy_Roach,

 

Try to do the following with a button by putting the following in on the onselect.

UpdateContext({cursel:!cursel})

This will change the variable value from true to false and vice versa.

 

If you use a toggle control, then you don't have to set a variable with the value as the toggle itself has a value of true or false. This can be referenced in the visible property of the other controls: Toggle1.Value

 

Let me know if you don't come right.

 

 

 

Hi! Thanks so much! I've made the change to OnSelect to: UpdateContext({cursel:!cursel})

That's got the toggle working but it's backwards of what I want.  So close! How would I reverse it?

 

I'm pretty new to this and not sure what youj mean about the second part.  In the visible field for the other controls I have cursel.

 

 

Hi @Christy_Roach

 

To reverse it you can specify !cursel on the visible property. Tihs will inverse true and false, so if the cursel is true, !cursel will return false, and vice versa.

 

Let me know if you don't come right.

v-xida-msft
Community Support
Community Support

Hi @Christy_Roach,

Based on the needs that you mentioned, I think a global variable could achieve your needs.

I have made a test on my side, please take a try with the following workaround:5.JPG

 

6.JPG

 

7.JPG

Set the OnVisible property of the screen to following:

If(Toggle1.Value = true, Set(IsShow, true), Set(IsShow, false))

On your side, you should type:

If(Toggle1.Value = true, Set(cursel, true), Set(cursel, false))  /* <-- Toggle1 represents the Toggle control on your side */

Set the OnSelect property of the Toggle control to following:

If(Toggle1.Value=true, Set(IsShow, true), Set(IsShow, false))

On your side, you should type:

If(Toggle1.Value = true, Set(cursel, true), Set(cursel, false))  /* <-- Toggle1 represents the Toggle control on your side */

Set the Visible property of the Label control to following:

IsShow

On your side, you should set the Visible property of the subsequent fields to following:

cursel

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Its unfortunately, still backward.  It's displaying and removing the field toggling the opposite direction.  The first field "event name" hides with !cursel in the visible fields.  Would the OnSelect formula for the toggle still be UpdateContext({cursel:!cursel})?  See second picture.Screenshot2.png

screenshot1.png

 

 

Hi @Christy_Roach

 

I would suggest not setting the context variable during the onselect event of the toggle. Just access the value of the toggle directly.

 

If you use a toggle control, then you don't have to set a variable with the value as the toggle itself has a value of true or false. This can be referenced in the visible property of the other controls: Toggle1.Value. This will show the control if the Toggle is 'On' and hide it is it is 'Off'. If you want to show the control when the toggle is 'Off' and hide it when the toggle is 'On', you can use !Toggle.Value in the visible property of the controls.

 

 

Perfect! Thanks! It's working!

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (3,422)