cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dougi
Level: Powered On

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
dougi
Level: Powered On

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
Super User
Super User

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})