3

I'm using lightning:recordViewForm and I realized that there is a bit delay. I was reading a lot here and in google but can't find any solution to this.

I thought on adding a spinner on my component just to be a little bit user friendly meanwhile data is loading.

Do you have any idea to implement it?

<lightning:recordViewForm aura:id="auraID"
                                  recordId="{!v.recordId}"
                                  objectApiName="Object__c" 
                                  density="comfy" >
            <div class="slds-grid slds-wrap">
                <div class="slds-col slds-size_3-of-12">
                    <lightning:outputField variant="label-stacked" fieldName="any_field"/>
                </div>
                <div class="slds-col slds-size_3-of-12">
                    <lightning:outputField variant="label-stacked" fieldName="Tother__c"/>
                </div>

                <div class="slds-col slds-size_6-of-12">
                    <lightning:outputField variant="label-stacked" fieldName="thelast__c"/>
                </div>
            </div>
        </lightning:recordViewForm>

1 Answer 1

2

For this purpose, you will need onload event. But this event is not available on recordViewForm - you can instead use recordEditForm.

Here is the sample code:

<lightning:spinner aura:id="spinner" variant="brand" />

<lightning:recordEditForm recordId="{!v.recordId}" 
                          objectApiName="Account"
                          onload="{!c.handleLoad}">
    <lightning:messages />
    <lightning:outputField fieldName="Name" />
</lightning:recordEditForm>

controller.js:

handleLoad : function(component, event, helper){
    $A.util.addClass(component.find("spinner"), "slds-hide");    
},
3
  • Thanks salesforce-sas for your soon reply. Using editForm is a way to solve but i'm not sure if the best. Aug 23, 2019 at 15:53
  • 1
    As you can see in the documentation, we can use outputField also - there is absolutely no problem. Note that this form uses LWC form (shown in doc link) behind the scenes (confirmed from sf support - unofficial). Aug 26, 2019 at 8:01
  • This doesnn't work for me, onload handler is having spinner implementation. However, it flickers for few seconds before loading the record edit form. This doesn't give a good user experience. do we have any other workaround for this? Jan 17 at 2:59

You must log in to answer this question.

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