I'm currently working on a form using lightning:RecordEditForm tag. I'm using lightning:inputField tag to display Account's BillingAddress fields (country code, state code, street, city, zip/code).

<lightning:recordEditForm objectApiName="Account" >
    <lightning:inputField aura:id="address" fieldName="BillingAddress"/>

BillingAddress with LightningInputfield

I would like to prepopulate address fields, for instance the country field with the user's country code.

I know that when trying to get address data in my javascript controller, I have to JSON.stringify the value to display it in console.logs :

var address = component.find("address").get("v.value");

I get the following results :


So I tried to set the component's value with a pre-constructed map, but no impact.

Does anyone know how I can achieve this ? Thanks !


Typically, I've found that if you can access an JS Object's property (in your case, BillingCity), then you can set the value like the following.

Then, the last bit where you component.set() actually (re)initializes the render cycle so that the view gets the new values you just assigned.

var addressValues = component.find("address").get("v.value");


addressValues["BillingCity"] = "Some City";
addressValues["BillingStateCode"] = "CA";

component.find("address").set("v.value", addressValues);
  • Hi tsalb, thanks for your answer. Indeed, I tried to set values like you showed above, but I get the following error : [Cannot set property 'BillingCity' of undefined]. Console.log displays "undefined", therefore the JS object is not defined yet – Sohaib FAROOQ Aug 10 '18 at 8:49
  • This is linked to the fact that I'm trying to prepopulate the field during doInit method. However, when I try to do it via a button, nothing happens (fields still empty) – Sohaib FAROOQ Aug 10 '18 at 9:11

I was playing around with this and I noticed it doesn't update the data back on the UI only for compound fields. Then I came across this in documentation - https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_records_create.htm?search_text=compound - it says that we need to provide individual fields as separate inputs.

I tried the below code and it does pre-populate

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="newAddress" type="Map" />
    <lightning:recordEditForm recordId="0011n00002OKKIYAA5" objectApiName="Account" onload="{!c.handleCreateLoad}">
        <lightning:inputField aura:id="city" fieldName="BillingCity" />

    handleCreateLoad: function (component, event, helper) {
        var city = component.find("city").get("v.value");
        city = "New York";
        component.find("city").set("v.value", city);

Hope this helps!

Best, Vishal

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.