function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ankit SaxenaAnkit Saxena 

Correct label for lookup in lightning recordform

Guys,

Currently lightning:recordForm doesn't show correct label for related fields. e.g if we try to render 'Case Owner' & 'Account Name' in record form for case object, we have to pass 'OwnerID' & 'AccountID' in list of fields. It renders field labels as 'OwnerId'. How to get this correct. Also how can i get other account fields on case, like account.address etc...

Thanks
Khan AnasKhan Anas (Salesforce Developers) 
Hi Ankit,

Greetings to you!

-> You can use the lightning:outputField variant of "label-hidden" along with a label tag to achieve this.
 
<label for="aid">Account Name</label>
 <lightning:outputField aura:id="aid" fieldName="AccountId" variant="label-hidden"/>
 
<label for="cid">Contact Name</label>
<lightning:outputField aura:id="cid" fieldName="ContactId" variant="label-hidden"/>

-> If you are using lightning:inputField, then variant="label-hidden" is not working as of now. However, you can use CSS like this:

Component:
<label for="aid">Account Name</label>
<lightning:inputField aura:id="aid" fieldName="AccountId" variant="label-hidden"/>

CSS:
.THIS label.slds-form-element__label {
    display : none;
    visibility : hidden;
}

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas