Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<aura:event type="COMPONENT" description="On record selection">
<aura:attribute name="childObjectName" type="String"/>
<aura:attribute name="fieldName" type="String"/>
<aura:attribute name="selectedRecordId" type="String"/>
</aura:event>
<aura:component>
<aura:attribute name="childObjectName" type="String" required="true"/>
<aura:attribute name="fieldName" type="String" required="true"/>
<aura:attribute name="selectedRecordId" type="String"/>
<aura:registerEvent name="onSelectEvt" type="c:CustomLookupSelectionEvt"/>
<lightning:recordEditForm
onload="{!c.setSelectedRecordId}"
objectApiName="{!v.childObjectName}">
<lightning:inputField aura:id="lookupField" variant="label-stacked" fieldName="{!v.fieldName}" onchange="{!c.fireOnSelectEvt}"/>
</lightning:recordEditForm>
</aura:component>
({
setSelectedRecordId: function(component, event, helper) {
var selectedRecordId = component.get("v.selectedRecordId");
component.find("lookupField").set("v.value", selectedRecordId);
},
fireOnSelectEvt : function(component, event, helper) {
var cmpEvent = component.getEvent("onSelectEvt");
cmpEvent.setParams({
"childObjectName": component.get("v.childObjectName"),
"fieldName": component.get("v.fieldName"),
"selectedRecordId": component.find("lookupField").get("v.value")
});
cmpEvent.fire();
}
})
<!--aura Handler-->
<aura:handler name="onSelectEvt" event="c:CustomLookupSelectionEvt" action="{!c.getLookUpValues}"/>
<c:CustomLookupStd
selectedRecordId="{!v.projectId}"
childObjectName="Contact"
fieldName="Project_in_Contact__c"/>
{
getLookUpValues : function(component, event, helper){
let fieldName = event.getParam("fieldName");
let projectId = event.getParam("selectedRecordId");
component.set("v.projectId", projectId);
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.