You need to sign in to do that
Don't have an account?
Force:inputfield doesn't render lookup value when used with wrapper in lightning?
I am rendering Accounts with their contacts in lightning component and showing account lookup field on child contacts But account lookup is not coming using force:inputfield in the contact section. However, when I printed the accountid on page, it's coming but lookup not rendering.
Please help and find the below code!
<aura:component controller="Account_with_contacts_controller" implements="force:appHostable,flexipage:availableForAllPageTypes">
<aura:attribute name="listaccount" type="Account_with_contacts_controller.Wrapper_Account[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="contact" type="Contact"
default="{ 'sobjectType': 'Contact' }"/>
<div class="slds-grid slds-m-around--medium ">
<table class="slds-table slds-table--bordered slds-max-medium-table--stacked">
<thead>
<tr class="slds-text-heading--label">
<th scope="col"> </th>
<th scope="col">ID </th>
<th scope="col">Name</th>
<th scope="col">Phone</th>
<th scope="col">Billing City</th>
</tr>
</thead>
<tbody>
<aura:renderIf isTrue="{!v.listaccount.length!=0}">
<aura:iteration items="{!v.listaccount}" var="item" indexVar="i">
<tr>
<td>
</td>
<td>
<label class="slds-checkbox">
<ui:inputCheckbox class="selector" aura:id="{!i}" value="{!item.selected}" change="{!c.selectcheckbox}"/>
<span class="slds-checkbox--faux"></span>
</label>
</td>
<td><ui:inputtext class="field" value="{!item.Name}"/></td>
<td><ui:inputtext class="field" value="{!item.Phone}"/></td>
<td><ui:inputtext class="field" value="{!item.BillingCity}"/></td>
<aura:iteration items="{!item.Contacts}" var="contactitem" indexVar="j">
<tr>
<td>
</td>
<td><ui:inputtext class="field" label="name" value="{!contactitem.Name}"/></td>
<td width="50%">{!contactitem.AccountId}<force:inputField value="{!contactitem.AccountId}"/> </td>
<td><ui:inputtext class="field" label="phone" value="{!contactitem.Phone}"/></td>
<td><ui:inputtext class="field" value="{!contactitem.Description}"/></td>
</tr>
</aura:iteration>
</tr>
</aura:iteration>
</aura:renderIf>
</tbody>
</table>
</div>
<div>
<button style="float:centre" class="slds-button slds-button--brand slds-m-bottom--large slds-align--absolute-center btn-lg" onclick="{!c.UpdateAccounts}">Update Accounts</button>
<br/>
</div>
</aura:component>
Please help and find the below code!
<aura:component controller="Account_with_contacts_controller" implements="force:appHostable,flexipage:availableForAllPageTypes">
<aura:attribute name="listaccount" type="Account_with_contacts_controller.Wrapper_Account[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="contact" type="Contact"
default="{ 'sobjectType': 'Contact' }"/>
<div class="slds-grid slds-m-around--medium ">
<table class="slds-table slds-table--bordered slds-max-medium-table--stacked">
<thead>
<tr class="slds-text-heading--label">
<th scope="col"> </th>
<th scope="col">ID </th>
<th scope="col">Name</th>
<th scope="col">Phone</th>
<th scope="col">Billing City</th>
</tr>
</thead>
<tbody>
<aura:renderIf isTrue="{!v.listaccount.length!=0}">
<aura:iteration items="{!v.listaccount}" var="item" indexVar="i">
<tr>
<td>
</td>
<td>
<label class="slds-checkbox">
<ui:inputCheckbox class="selector" aura:id="{!i}" value="{!item.selected}" change="{!c.selectcheckbox}"/>
<span class="slds-checkbox--faux"></span>
</label>
</td>
<td><ui:inputtext class="field" value="{!item.Name}"/></td>
<td><ui:inputtext class="field" value="{!item.Phone}"/></td>
<td><ui:inputtext class="field" value="{!item.BillingCity}"/></td>
<aura:iteration items="{!item.Contacts}" var="contactitem" indexVar="j">
<tr>
<td>
</td>
<td><ui:inputtext class="field" label="name" value="{!contactitem.Name}"/></td>
<td width="50%">{!contactitem.AccountId}<force:inputField value="{!contactitem.AccountId}"/> </td>
<td><ui:inputtext class="field" label="phone" value="{!contactitem.Phone}"/></td>
<td><ui:inputtext class="field" value="{!contactitem.Description}"/></td>
</tr>
</aura:iteration>
</tr>
</aura:iteration>
</aura:renderIf>
</tbody>
</table>
</div>
<div>
<button style="float:centre" class="slds-button slds-button--brand slds-m-bottom--large slds-align--absolute-center btn-lg" onclick="{!c.UpdateAccounts}">Update Accounts</button>
<br/>
</div>
</aura:component>
The default Salesforce components do not support lookup, you have to build your custom component. However you can reuse code from here,
http://www.sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com
I have created one below component in past which is rendering lookup and it's working fine.
<aura:component controller="ContactController">
<aura:attribute name="contact" type="Contact"
default="{ 'sobjectType': 'Contact' }"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div aura:id="lookup-pill" class="slds-pill-container">
<span class="slds-pill" style="width:100%">
<div class="slds"> <force:inputField aura:id="contactName" class="slds-select"
value="{!v.contact.AccountId}"/> </div>
</span>
</div>
</aura:component>
So the same thing I am using in my affected component but it's not working with the wrapper?