cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

Manually Set Toggle.Value

Hi, 

 

Is there a way to manually set the toggle value?

 

Example ... I want to use 3 Toggle Buttons the way a Radio Control works, if you Select one the others are UnChecked.

 

Ideally I'd like to use a Toggle rather than a Radio Control as the backend has 3 separate fields for the data, where as a Radio button would only be updating 1 field. Also for consistancy in the App using a Toggle would be better. 

 

I've been playing with Variables but haven't found a way to set the .Value field of a Toggle

 

Cheers

2 REPLIES 2
Highlighted
Advocate I
Advocate I

Re: Manually Set Toggle.Value

So I've got a terrible hack of a solution, surely there has to be a better way to do this ...

 

Toggle1.OnCheck = UpdateContext({ToggleChanged:true});UpdateContext({Toggle1Check:true});UpdateContext({Toggle2Check:false})

 

Toggle1.Default = If(ToggleChanged = true, false, Parent.Default)

Toggle2.Default = Same as above

 

Toggle1.Reset = If(Toggle1Check = false, true, false)

Toggle2.Reset = If(Toggle2Check = false, true, false)

 

So basically

1. When a Toggle is Checked, a variable is set to true and the other Toggles variable is set to false

2. The Reset Function is evaluated and if the variable is now false the Toggle is Reset

3. The Reset changes the value back to the Default which is also updated by the variable. Initially it uses the Parent.Default but if any changes have been made it sets the Default to False

 

It's a terrible solution but kind works, it's also a pain when you have a lot of Toggles you want to group.

 

If only there was a Toggle.Value Event that could be updated as easily as a TextBox.Text

 

If anyone has any better solutions, please post them

Highlighted
Memorable Member
Memorable Member

Re: Manually Set Toggle.Value


@dougi wrote:

So I've got a terrible hack of a solution, surely there has to be a better way to do this ...

 

Toggle1.OnCheck = UpdateContext({ToggleChanged:true});UpdateContext({Toggle1Check:true});UpdateContext({Toggle2Check:false})

 

Toggle1.Default = If(ToggleChanged = true, false, Parent.Default)

Toggle2.Default = Same as above

 

Toggle1.Reset = If(Toggle1Check = false, true, false)

Toggle2.Reset = If(Toggle2Check = false, true, false)

 

So basically

1. When a Toggle is Checked, a variable is set to true and the other Toggles variable is set to false

2. The Reset Function is evaluated and if the variable is now false the Toggle is Reset

3. The Reset changes the value back to the Default which is also updated by the variable. Initially it uses the Parent.Default but if any changes have been made it sets the Default to False

 

It's a terrible solution but kind works, it's also a pain when you have a lot of Toggles you want to group.

 

If only there was a Toggle.Value Event that could be updated as easily as a TextBox.Text

 

If anyone has any better solutions, please post them


 

 

Might be helpful but you can flip a true false and even combine update values into single lines with the following:

 

UpdateContext({Toggle1Check:!Toggle1Check, Toggle2Check:!Toggle2Check})

 

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (5,420)