4

Running into the issue and wondered if I am doing something wrong, have incorrect expectations, etc.

When using the or operator in a lightning component (including lightning out) to evaluate values in either an if statement or isTrue property I am observing that if you have more than two variables the or is not evaluated correctly.

Take the below example that illustrates this:

<aura:component description="myORExample" implements="flexipage:availableForAllPageTypes">

    <aura:if isTrue="{!or(false,false,true)}">
        <p>Three Or Evaluations with last true</p>
    </aura:if>

    <aura:if isTrue="{!or(true,false,false)}">
        <p>Three Or Evaluations with first true</p>
    </aura:if>

    <aura:if isTrue="{!or(false,true,false)}">
        <p>Three Or Evaluations with second true</p>
    </aura:if>

    <aura:if isTrue="{!or(false,true)}">
        <p>Two Or Evaluations with one true</p>
    </aura:if>

</aura:component>

enter image description here

Placing this on a page layout you will see that the first example is evaluated to false and thus does not display. It clearly should evaluate to true as the third value is true.

Seems that only the first two variables are evaluated in the or operator.

Bug or working a designed?

2
  • Well this documentation says "Returns true if either one of the arguments is true"; "either" implies only 2 to me (vs "any").
    – Keith C
    Commented Jun 8, 2017 at 16:45
  • My search is failing lately....thank for the dupe @sfdcfox
    – Eric
    Commented Jun 8, 2017 at 17:26

1 Answer 1

5

You can use || in place of the OR() operation. So your code would look like the below code:

<aura:component description="myORExample" implements="flexipage:availableForAllPageTypes">

<aura:if isTrue="{!false || false || true}">
    <p>Three Or Evaluations with last true</p>
</aura:if>

<aura:if isTrue="{!true || false || false}">
    <p>Three Or Evaluations with first true</p>
</aura:if>
<aura:if isTrue="{!false || true || false}">
    <p>Three Or Evaluations with second true</p>
</aura:if>

<aura:if isTrue="{!false || true}">
    <p>Two Or Evaluations with one true</p>
</aura:if>

3
  • This is indeed the workaround that I am using so appreciate your confirmation. Upvoting but not accepting as the question was about why OR was not working. The answer is important however, just wanted to explain my thoughts....
    – Eric
    Commented Jun 8, 2017 at 17:26
  • 1
    This also applies to the and() operator. If your evaluating in markup you must escape the && as &amp;&amp;. eg. isTrue="{var1 &amp;&amp; var2 &amp;&amp; var3}" Commented Jan 31, 2018 at 21:16
  • kudos Dan!! great workaround Commented Mar 14, 2019 at 11:05

Not the answer you're looking for? Browse other questions tagged .