[SalesForce] Use variable from lightning:recordEditForm in aura:if

I would like to know if it's possible to evaluate the expression from the RecordEditForm.

This component's "else" is never hit. Are aura if tags supported within RecordEditForms?

Comments__c is a Text field.

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
<aura:attribute name="anyAccount" type="String" access="public"/>

 <lightning:card class="slds-text-heading_small slds-card_boundary" title="{!'Account Type : ' + v.anyAccount }" >
     
    <lightning:recordEditForm recordId="{!v.recordId}"
                          aura:id="editRecord"
                          objectApiName="Account"
                         >
        <!-- onsubmit belongs to the button within the form -->
        <center><strong><lightning:outputField fieldName="Name" /></strong></center>
        <lightning:inputField fieldName="Industry" />
        <lightning:outputField fieldName="Industry" />
       
        <aura:if isTrue="{!empty(v.Comments__c)}">
            <lightning:inputField fieldName="Send_To_ERP__c" />
            <aura:set attribute="else">
                This Account is in ERP
            </aura:set>
        </aura:if>
     </lightning:recordEditForm>        
        <center><lightning:button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Update Account" onclick="{!c.update}" /></center> 
     
 </lightning:card>

</aura:component>

You should see different outcomes

enter image description here

Best Answer

modify your code to below format. you missed value attribute and empty check

    <aura:component implements="flexipage:availableForRecordHome,force:hasRecordId">
<aura:attribute name="anyAccount" type="String" access="public"/>
<aura:attribute name="commentchk" type="Boolean" default="false"/>

 <lightning:card class="slds-text-heading_small slds-card_boundary" title="{!'Account Type : ' + v.anyAccount }" >

    <lightning:recordEditForm recordId="{!v.recordId}"
                          aura:id="editRecord"
                          objectApiName="Account"
                          onload="{!c.handleOnload}"
                         >
        <!-- onsubmit belongs to the button within the form -->
        <center><strong><lightning:outputField fieldName="Name" /></strong></center>
        <lightning:inputField fieldName="Industry" />
        <lightning:outputField fieldName="Industry" />

        <aura:if isTrue="{!v.commentchk)}">
            <lightning:inputField fieldName="Send_To_ERP__c" />
            <aura:set attribute="else">
                This Account is in ERP
            </aura:set>
        </aura:if>
     </lightning:recordEditForm>        
        <center><lightning:button class="slds-m-top_small" variant="brand" 
           type="submit" name="update" label="Update Account" onclick=" 
            {!c.update}" /></center> 

        </lightning:card>

       </aura:component>

controller.js

 ({
   handleOnload : function(component,event,helper){
   var recUi = event.getParam("recordUi");
    if($A.util.isEmpty(recUi.record.fields["Comments__c"].value)){
     component.set("v.commentchk", true);
    }

   },
})
Related Topic