0

I have implemented the following custom lookup component tailoring to my needs.

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

I am using this component in iteration (which shows related object records). Lookup is displayed as one of the fields correctly. However I am failing to retrieve the lookup values on the javascript. I am always getting the first selected value on this lookup for every other record.Below is the code:

    <aura:attribute name="selectedLookUpRecord" type="User" default="{}"/>
 <aura:iteration items="{!v.dataRows}" var="recData">
  <td data-label="Start Date">
  <lightning:inputField fieldName="Start_Date__c" value="{!recData.Start_Date__c}" />
</td> 
<td>
<c:customLookupController IconName="standard:user" selectedRecord="{!v.selectedLookUpRecord}" />
</td>
</aura:iteration>

Javascript:

for( var i=0; i < component.find("mSelected").length; i++) {
            if( component.find("mSelected")[i].get("v.value") == true ){
             dataRecs[i].OwnerId = component.get("v.selectedLookUpRecord")[i].Id;
            console.log(component.get("v.selectedLookUpRecord")[i].Id);
        }  }

Is there any way to cater this component for multiple records selected at the same time?

0

You've bound all the lookups to a single attribute ("variable"), which is why this is happening. Instead, you need a list, and it should be the same list the iterator is currently working with:

<aura:iteration items="{!v.dataRows}" var="recData">
  <c:customLookupController iconName="standard:user" selectedRecord="{!recData.selectedRecord}" />
</aura:iteration>

Note here that I'm altering your "dataRows" attribute to have a reference to a "selectedRecord". You'll need this to get the list of users back.

You'll need to extract the data from the original list directly. What that means exactly depends on how the dataRows attribute is populated and defined.

  • I updated my code. dataRows in the iteration actually holds custom object records. Look up component I am using is an independent one. So once User enters the value on this lookup I need to update the ownerId of the custom object with the entered values respectively on my js controller. @sfdcfox – Kanikala Oct 29 '18 at 16:17
  • @Kanikala Sure, my answer is still correct, just change {!recData.selectedRecord} to {!recData.OwnerId}. You'll need to do some post-processing in your controller, if I remember this custom lookup feature correctly, because the lookup component returns an entire record instead of just the ID. – sfdcfox Oct 29 '18 at 16:22

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.