11

As I use the client side to enforce various pieces of business logic with aura:if statements, I'm finding that a given formula operator cannot handle more than two parameters.

For example, this works:

<aura:if isTrue="and(v.myAttributeString == 'Open', v.myAttributeBoolean == true)">
    //do some stuff
</aura:if>

But the following does not work (or at least the third "v.myAttributeSecondString" is not evaluated):

<aura:if isTrue="and(v.myAttributeString == 'Open', v.myAttributeBoolean == true, v.myAttributeSecondString == 'Yes')">
    //do some stuff
</aura:if>

Has anyone seen the same effect occur? Any documentation on this? Am I crazy and this actually does work, just not for me?

Thanks!

11

Yes, it's a known bug/limitation of Expression Operators. You can only evaluate two parameters in and and or expressions. You'll probably want to consider setting an attribute evaluated by your controller to determine the final logic behavior as a workaround.

2
  • Thanks! Do you have a reference to the known issue for tracking purposes? May 31 '17 at 16:42
  • 2
    @techbusinessman "Known Issue" might be a bit strong. I know that it's broken, and that people at salesforce.com know it's broken, but I don't know of a public Known Issue that you can sign up for. Perhaps you should submit a case and see if Dev Support will give you one.
    – sfdcfox
    May 31 '17 at 16:51
6

Two things to add:

1) From a JavaScript perspective it makes sense. In JS extra parameters to a function are accepted and ignored. So and(true, true, false) returns true because it's a two-parameter function.

2) For what it's worth, you can chain any number of ANDs with && but unlike Visualforce you have to escape it to conform with XML rules. So {!true &amp;&amp; true &amp;&amp; false} correctly yields false. Note that for chaining multiple ORs you can just use || straight up.

1

Agree with @Sfdcfox And nice options from Charles T

So there is one more solution that I follow

You can wrap one and condition inside another since lightning and function work with only 2 parameters. below is the example

{!and( and(condition 11, condition 12), condition 2)}
{!and( and( and(condition 111, condition 112), condition 12), condition 2)}
1

Here's the official documentation regarding these limitations: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_operators.htm

"If you have more than two arguments, you can chain multiple && operations."

"If you have more than two arguments, you can chain multiple || operations."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.