0

I'm trying to set the default value of lookup for

I'm getting the error when I try to set value:

var value = [{
type: 'Account',
id: "0014343234543",
label: "Related To"
}];
component.find("lookupaccount").get("v.body")[0].set("v.values",value);

My force:inputField is inside aura:if and on click of a button if condition sets to true and lookup component renders in the component.

Component:

<aura:if isTrue="{!v.isTrue}">
   <div class="slds-show slds-p-around--medium">
      <div class="slds-grid slds-wrap">
         <force:inputField aura:id="lookupaccount" value="{v.obj.AccountId}" />
</div>
</div>
</aura:if>

Controller:

buttonclick : function(component,event,helper){
   component.set("v.isTrue",true);
   var value = [{
    type: 'Account',
    id: "0014343234543",
    label: "Related To"
    }];
    component.find("lookupaccount").get("v.body")[0].set("v.values",value);

}

1 Answer 1

0

you have an aura:if and then force:inputField; hence your code is not working. Please try below.

<aura:if isTrue="{!v.isTrue}">
   <div class="slds-show slds-p-around--medium">
      <div class="slds-grid slds-wrap">
         <force:inputField aura:id="lookupaccount" value="{v.obj.AccountId}" />
      </div>
   </div>
</aura:if> 

Controller Code:

buttonclick : function(component,event,helper){
   component.set("v.isTrue",true);
   var populateAction = component.get('c.populateLookUp');
   $A.enqueueAction(populateAction); 
},
populateLookUp :function(component,event,helper){
var value = [{
    type: 'Account',
    id: "0014343234543",
    label: "Related To"
    }];
    component.find("lookupaccount").get("v.body")[0].set("v.values",value);
}

Please check if this works for you. You are trying to access something for which DOM is not ready yet. So, you need to call it asynchronously.

2
  • I’m still seeing undefined value Commented Jan 20, 2020 at 10:04
  • Instead of aura:if use css to show hide then the DOM will be defined. Commented Jan 20, 2020 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .