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

Hide an element when multiple conditions are true

I am experiencing an erratic response from Power Apps and I think it's a bug.

I have 4 checkboxes. If any of the checkboxes are true, I show an extra element. If all checkboxes are false, I hide that element.

Simple, right?

 

To deal with the correct value when the form is initially launched, I set the screen's  On Visible property to:

 

 

If(Checkbox18.Value || Checkbox26.Value || Checkbox3.Value || Checkbox6.Value ||Checkbox4.Value = true,Set(hidespacers,true),Set(hidespacers,false));

 

 

 

I set the Visible property of the element I need to be hidden to:

 

 

hidespacers

 

 

 
I set the OnSelect property of each checkbox to:

(the example below is for Checkbox3)

 

If(hidespacers=true && Checkbox6.Value = false && Checkbox26.Value = false &&
Checkbox18.Value = false &&
Checkbox4.Value = false,
Set(hidespacers,false),Set(hidespacers,true))

 

 

 
This acts very strangely.
- If I check any of the checkboxes, the element is visible, great.
- if I uncheck all checkboxes, the element is still visible, not great. 
- If I spam the checkboxes and set multiple ones checked and then uncheck them one by one, magically, it hides the element when the last one is unchecked.
- If I enter a new item, it works as it should.

What am I doing wrong? It worked just fine when I only had 2 checkboxes but now with 5 it doesn't.

1 ACCEPTED SOLUTION

Accepted Solutions
GarethPrisk
Resident Rockstar
Resident Rockstar

You can leverage simpler behavior formulas to accomplish this. You don't need to have a variable or anything.

 

I also recommend that you simplify your formula, by using the And() function.

 

In your case, you are showing the element whenever all of them are true. Set the Visible property of that element equal to:

 

And(
    Checkbox3.Value,
    Checkbox4.Value,
    Checkbox6.Value,
    Checkbox18.Value,
    Checkbox26.Value
)

 

 

View solution in original post

4 REPLIES 4
GarethPrisk
Resident Rockstar
Resident Rockstar

You can leverage simpler behavior formulas to accomplish this. You don't need to have a variable or anything.

 

I also recommend that you simplify your formula, by using the And() function.

 

In your case, you are showing the element whenever all of them are true. Set the Visible property of that element equal to:

 

And(
    Checkbox3.Value,
    Checkbox4.Value,
    Checkbox6.Value,
    Checkbox18.Value,
    Checkbox26.Value
)

 

 

View solution in original post

That doesn't make a difference.
Also, I'm showing the element when ANY checkbox is true. When they are all false, I hide the element.

I adjusted the formula but the result is the same. It makes the element visible but doesn't hide it on a subsequent click.

 

 

 

If(And(
    hidespacers = true,
    Checkbox18.Value = false,
    Checkbox4.Value = false,
    Checkbox6.Value = false,
    Checkbox26.Value = false
),
Set(hidespacers,false),Set(hidespacers,true))

 

 

 

I'm even displaying the result of each element to make sure I'm not going crazy and based on what I see, it should hide the element but it doesn't.

WorkHard_1-1625787282906.png

You misunderstood my response. You do not need the hidespacers variable. Checkboxes are inherently returning a True/False value as their Value. I was simply showing that they can be used directly, instead of through a variable.

 

However, your scenario may be more complicated than that. Sorry if I misunderstood.

 

Are these Checkboxes controls in a Gallery, or standalone in the form?

 

Also, using the OnSelect in a boolean control can introduce recursion if you're not careful. Behavioral formulas and functions can cause them to be unintentionally selected, causing an infinite loop.

 

Here is an example, which simply sets the Boolean variable based on the check for any of the Checkboxes being selected. It also has an example of a Counter, if you want to see if/when your OnSelect property may be invoked more times than you expected.

 

Set(
    gblBoolean,
    Or(
        Checkbox1.Value,
        Checkbox2.Value,
        Checkbox3.Value,
        Checkbox4.Value
    )
);
Set(
    gblChangeCounter,
    gblChangeCounter + 1
);

 


Also, using the OnSelect in a boolean control can introduce recursion if you're not careful.

I think that's exactly what's going on. Because if I spam the checkbox (check, uncheck them repeatedly) it then works normally. So I think me spamming the checkboxes breaks the loop.

I am attempting now to set up the counter you mentioned to see if that's true. I did run the Activity Monitor from the Advanced Tools Menu but it doesn't show any infinite events going on.
Update: No, the counter stays at 1 the entire time.


@GarethPrisk wrote:

You misunderstood my response. You do not need the hidespacers variable. Checkboxes are inherently returning a True/False value as their Value. I was simply showing that they can be used directly, instead of through a variable.


Ah, I see now, you are right. I just need the "Visible" property of the element set to the checkboxes state so that if any checkbox is true it would set the Visible to true, brilliant.

 

This worked, thank you.

 

Or(
    Checkbox3.Value,
    Checkbox4.Value,
    Checkbox6.Value,
    Checkbox18.Value,
    Checkbox26.Value
)

 

 

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!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,474)