-1

I have created a custom lookup based on below link:

http://www.sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/

code snippets:

<aura:component>
 <c:s360_customLookup objectAPIName="account" IconName="standard:account" 
selectedRecord="{!v.whatIdVal}" label="Related To" />
</aura:component>

In case of custom lookup value change,I have to pass that value to another component.How to Identify changes value in Custom Lookup


  <aura:component > 
 <aura:handler name="change" value="{!v.whatIdVal}" action="{!c.whatIdChanged}"/> 
<c:s360_customLookup objectAPIName="account" IconName="standard:account" selectedRecord="{!v.whatIdVal}" label="Related To"/> 
</aura:component>

Javscript:

({ 
   whatIdChanged:function(component, event, helper) { 
    alert('vall'); 
    } 
}) 
1

Just add a value change handler, the event will fire whenever the whatIdVal changes.

<aura:component > 
    <aura:attribute name="selectedLookUpRecord" type="sObject" default="{}"/>

    <aura:handler name="change" value="{!v.selectedLookUpRecord}" action="{!c.selectedLookupChanged}"/> 
    <c:s360_customLookup objectAPIName="account" IconName="standard:account" 
    selectedRecord="{!v.selectedLookUpRecord}" 
    label="Related To"/> 
</aura:component>

JS:

({ 
   selectedLookupChanged:function(component, event, helper) { 
        console.log('Selected record changed');
        console.log(JSON.stringify(component.get("v.selectedLookUpRecord")));
    } 
}) 

https://developer.salesforce.com/docs/component-library/bundle/aura:valueChange/documentation

2
  • I have updated the code below.alert is also not coming.I need selected record id Jun 1 '18 at 10:28
  • Can you edit your question and post it there as code snippet, its so hard to read code from comments. @AnnappaPH Jun 1 '18 at 10:29
1

Create an application or component event for tracking the lookup change. Register the event in your lookup component like below <aura:registerEvent name="onLookupChange" type="c:LookupChangeEvent"/> where c:LookupChangeEvent is the component or application event, you should create it. I prefer component event.

When the lookup value changes, the newly created events should be triggered with necessary params. Inside the lookup change handler defined under JS Controller,

var lookupChangeEvent = component.getEvent('onLookupChange');
lookupChangeEvent.setParams({"Id" : id}).fire(); 

The created component should be called with event handler parameter inside another component.

<aura:component>
    <c:s360_customLookup objectAPIName="account" IconName="standard:account" 
    selectedRecord="{!v.whatIdVal}" label="Related To" onLookupChange="{!c.lookupChangeHander}"/>
</aura:component>

Define the lookupChangeHander in the JS Controller to get the event params whenever the lookup changes.

lookupChangeHander: function(component, event, helper){
        var params = event.getParams();
        console.log(params.Id);
}

Please refer my blog for more details on lightning https://techevangel.com/2018/04/29/custom-lookup-component-for-lightning/

2
  • This will not work onLookupChange attribute should present in custom lookup..anyway thanks Jun 1 '18 at 10:13
  • I thought the custom component was owned by you. So I asked you to create that event handler and component event to handle the record lookup change. I have explained how it works.
    – Anil S
    Jun 1 '18 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.