5

I have been trying to pre-populate a lookup based lightning:inputField with a default value.

The code below renders a lookup field that works but I would like to be able to set a default contact in the field when it renders on the page. I have tried a lot of different ways to get this to go, but am at a loss. Any ideas?

<lightning:inputField fieldName="ContactId" aura:id="contactId"/>
  • If you don't mind, can you please post your code? As I am trying to implement the lightning:inputField, i.e. lookup field, I am getting a input box with a spinner right next to the magnifying glass(search). – Arnold Jr. May 23 '18 at 20:47
  • This is basically it. <aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes"> <lightning:recordEditForm objectApiName="Case"> <lightning:messages /> <lightning:inputField fieldName="ContactId" aura:id="input_field" value="0033D00000ONAN3"/> <lightning:button variant="brand" class="btn" type="submit" label="Create" /> </lightning:recordEditForm> </aura:component> – Tad May 23 '18 at 20:52
  • I tried to see if I can get a OOB lookup from Salesforce. Because, previously I have created a Custom Lookup. For now, I have just created a sample lightning component by reference this: lightning:inputField. I got a search box with a spinner right next to it. – Arnold Jr. May 23 '18 at 20:56
  • Do you have any of your code to share? – Tad May 23 '18 at 21:02
0

You can use value attribute to set a default value.

<lightning:inputField fieldName="ContactId" aura:id="contactId" value="00222Ayqz"/>

Source:

| improve this answer | |
  • That was the first thing that I tried. I tried both the 15 and 18 character ID of the contact that I wanted to default it to. Unfortunately that did not work. – Tad May 23 '18 at 19:38
0

Use on load event :

Try to set your input field value in client side controller.

({ handleCreateLoad: function (cmp, event, helper) { var nameFieldValue = cmp.find("input_field").set("v.value", "your ID here"); } })

| improve this answer | |

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.