cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Julien2
Super User
Super User

Toggle switches automatically based on a condition

Hello,

I have a PowerApps app connected to an SP List, and I want to switch On the toggle based on a column text value.

The condition should check if FirstMangSign (Single Line of Text) equals Signed, then the toggle should be switched automatically to On, and if the field was not filled to Signed then the toggle should be switched to Off.

Besides, I want to hide this toggle so the user will not be able to see it.

I have tried to implement the following function check property of the toggle:

Set(
    vNotSigned,
        IsBlank(
                First(
                        Filter(
                                'Purchase Order I', 
                                ID = SelectedReport.ID && 
                                FirstMangSign= "Signed"
                            )
                    )
                )
);

If(!vNotSigned, UpdateContext({Checked: true}),UpdateContext({Checked: false}))

And I have set the Default value of the toggle to Checked. (Which is the value that I have initialized)

Unfortunately, nothing happens and the toggle is always showing Off knowing that the SelectedReport ID in SP list the FirstMangSign column is signed.

Can please someone explains in detail and provide an example to achieve the above scenario?

Any help will be greatly appreciated.

Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @Julien2 ,

Where do you put your Set formula? Do you type your Set function within OnCheck property of Toggle control?

 

Currently, there is an known issue with the OnCheck property of the Toggle control -- Toggle.OnCheck, .OnUncheck, and OnChange fires when its value changes, regardless of user interaction. Please check the following thread for more details:

https://powerusers.microsoft.com/t5/Building-Power-Apps/Bug-When-using-Toggle-control-to-patch-a-col...

 

So please do not put your Set formula within the OnCheck property of Toggle control. Based on the needs that you mentioned, I think it is not necessary to initialize a variable to achieve your needs.

Please consider set the Default property of the Toggle control to following:

If(
   IsBlank(
           LookUp('Purchase Order I', ID = SelectedReport.ID && FirstMangSign = "Signed")
   ),
   false,
   true
)

 

In addition, you could also consider add a Checkbox control in your app to achieve your needs instead of this Toggle control.

 

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.

View solution in original post

2 REPLIES 2
v-xida-msft
Community Support
Community Support

Hi @Julien2 ,

Where do you put your Set formula? Do you type your Set function within OnCheck property of Toggle control?

 

Currently, there is an known issue with the OnCheck property of the Toggle control -- Toggle.OnCheck, .OnUncheck, and OnChange fires when its value changes, regardless of user interaction. Please check the following thread for more details:

https://powerusers.microsoft.com/t5/Building-Power-Apps/Bug-When-using-Toggle-control-to-patch-a-col...

 

So please do not put your Set formula within the OnCheck property of Toggle control. Based on the needs that you mentioned, I think it is not necessary to initialize a variable to achieve your needs.

Please consider set the Default property of the Toggle control to following:

If(
   IsBlank(
           LookUp('Purchase Order I', ID = SelectedReport.ID && FirstMangSign = "Signed")
   ),
   false,
   true
)

 

In addition, you could also consider add a Checkbox control in your app to achieve your needs instead of this Toggle control.

 

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.

Hello @v-xida-msft ,
Thanks for your advice. Currently, The toggle works as expected.

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 (1,923)