3

I had tried this on my own, but couldn't achieve the functionality of having multiple conditions checked using conditional 'OR' operator of an aura:if attribute.

I tried to render a div only when the value of a Text type aura attribute is equal to particular Text Strings. But, it didn't worked for me.

My code is as below :

<aura:attribute name="Text1" type="String"/>
<aura:if isTrue="{!OR(v.Text1=='Hello',v.Text1=='Bye')}">
<div>
ABCD
</div>
</aura:if>

I tried other combinations as well, like ;

<aura:if isTrue="{!v.Text1 =='Hello' || !v.Text1 =='Bye'}">
</aura:if>

But that also didn't worked. Do someone has any idea about how to make it work?

3
  • 1
    Your first attempt should work (with or(exp1,exp2) ) developer.salesforce.com/docs/atlas.en-us.lightning.meta/… Are you sure Text1 is getting the expected value?
    – Ranga
    Oct 9, 2018 at 13:56
  • Yes @Ranga, the expected value was received, but the content under aura:if was not displayed. Oct 11, 2018 at 13:16
  • is this still an issue it is working for me try upgrading your lightning component version. What I noticed the maximum number of condition supported is 1 like or( condition 1 , condition 2) is supported but or(condition 1, condition 2 , condition 3, condition 4) never works Oct 9, 2019 at 15:52

1 Answer 1

4

Try this:-

<aura:attribute name="Text1" type="String"/>
<aura:if isTrue="{!or(v.Text1=='Hello',v.Text1=='Bye')}">
       <div>
         ABCD
       </div>
</aura:if>

It will work. What you were doing wrong is your T is small in isTrue as it is case sensitive and also Hello and bye should be in single quotes when you are comparing an attribute to a string:

<aura:if istrue="{!OR(v.Text1=="Hello",v.Text1=="Bye")}">

change it to

<aura:if isTrue="{!or(v.Text1=='Hello',v.Text1=='Bye')}">
3
  • That is not the case, Sanket, I tried what you had suggested, its just that while posting the question, I didn't care about the syntax. What you have suggested is what I had tried already. Oct 11, 2018 at 13:39
  • Are you setting the value of your attribute Text1 in client side controller with the value you mentioned in your code? Oct 11, 2018 at 16:24
  • Yes, the javascript controller is the one which is setting the values into these attriubutes. Oct 12, 2018 at 11:43

You must log in to answer this question.

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