0

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

1
  • Think you will need an aura:attribute and to reference it using v.. But I'm unsure what the best pattern is. See e.g. salesforce.stackexchange.com/questions/254667/… and the comment "Just set the attribute on onload of the record edit form and it will work" which sounds like a good way to go.
    – Keith C
    Feb 11, 2020 at 19:03

1 Answer 1

0

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

   },
})
4
  • Hi @sdandamud1 it still doesn't display the else condition for one of the Accounts. I've updated my code and added a picture
    – user69530
    Feb 11, 2020 at 20:37
  • yes, because you don't have Comments__c aura attribute, if you want validate c with loaded record details data you need to customize by using onload event of recordeditform . updated my answer let me know still if uhave any issue.
    – sdandamud1
    Feb 11, 2020 at 22:48
  • Thank you, this worked!
    – user69530
    Feb 12, 2020 at 19:32
  • Is there any documentation on what the recordUI returns? I can't find any documentation from salesforce on when, how to use this
    – user69530
    Feb 14, 2020 at 20:51

You must log in to answer this question.

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