1

How can I combine two if condition in one statement in Lightning components.

<aura:if  isTrue="{!v.wrp.ObjectApiNAme!='Pay_Element_Master__c'}">
            <aura:if  isTrue="{!v.wrp.ObjectApiNAme!='CTC_Master__c'}">
                 <aura:if  isTrue="{!v.wrp.ObjectApiNAme!='Section_Master__c'}">
                <lightning:select name="select" label=" " aura:id="o" >
                    <option value="">None</option>
                </lightning:select>
            </aura:if>
        </aura:if>
        </aura:if>

1 Answer 1

5

try lightning and function

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_functions.htm

<aura:if  isTrue="{!and(v.wrp.ObjectApiNAme!='Pay_Element_Master__c', 
                        v.wrp.ObjectApiNAme!='CTC_Master__c', 
                        v.wrp.ObjectApiNAme!='Section_Master__c')}">
    <lightning:select name="select" label=" " aura:id="o" >
        <option value="">None</option>
    </lightning:select>
</aura:if>

Above code is not working now.

Updated code - 20-02-2018

<aura:if  isTrue="{!and(
                        and(v.wrp.ObjectApiNAme!='Pay_Element_Master__c', v.wrp.ObjectApiNAme!='CTC_Master__c'), 
                        v.wrp.ObjectApiNAme!='Section_Master__c')
                    )}">
        <lightning:select name="select" label=" " aura:id="o" >
            <option value="">None</option>
        </lightning:select>
    </aura:if>

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)}

Note: Since it is javascript, don't user capital AND. Use only small and

3
  • your welcome @AnnappaPH
    – Ratan Paul
    Commented Apr 3, 2017 at 5:31
  • 1
    Sorry to only read this a year later. If this code is live in your org the logic may be wrong. Actually the Lightning expressions and, or only take two arguments and ignore any after the 2nd. You can use && for AND but in Lightning markup it must be XML-escaped, so it will actually be &amp;&amp;.
    – Charles T
    Commented Feb 19, 2018 at 16:32
  • Someone minused my comment after I entered it. Please refer here for further confirmation that and(param1,param2,param3) in Lightning is treated as only and(param1,param2). salesforce.stackexchange.com/questions/176835/… "Yes, it's a known bug/limitation of Expression Operators. You can only evaluate two parameters in and and or expressions."
    – Charles T
    Commented Feb 19, 2018 at 20:29

You must log in to answer this question.

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