1

Is there any way to display an address field such as Account.MailingAddress on a custom Lightning component? I am overriding the New Account button with a custom Lightning component and I want to let users take advantage of the built-in Search Address feature as well as the State/Country picklists.

  • Mailingaddress is realted to contact AFAIK. What is stopping you from querying compound fields like select id,name,BillingStreet,Billingcity,BillingPostalCode from apex controller and showing on the component ? – Rao Jul 18 '17 at 23:39
  • I don't believe there is any out of the box solution for what you're looking for. You'd likely have to spin it up yourself using the individual fields Rao mentioned. – Antonio Manente Jul 18 '17 at 23:54
  • @Rao I am overriding the New Account button, so there's nothing to query for. Regardless, I can display regular text inputs, but I want to utilize the built-in Google Address Search functionality. – Mossi2 Jul 19 '17 at 0:17
  • Maps and Location Settings are not available in Development org, so I cannot validate the autocompletion feature. I assume you are using force:inputField. In my org I can use <force:inputField value="{!v.acc.BillingAddress}"/> and I see the billing address fields, do you get the autocompletion when you choose this method? – Rao Jul 19 '17 at 2:06
  • @Rao I am able to display them using force:inputField, however the generated compound fields have no labels and the State/Country picklists are not even showing up. – Mossi2 Jul 19 '17 at 18:49
2

I just got a response from SFDC R&D and there is a confirmed bug with address fields in Lightning components:

https://success.salesforce.com/issues_view?id=a1p3A000000EAi2

1

There is an important thing to note when using force:inputField. It will only work if it is directly under the aura:component tag. There is a workaround for this though.

First, this knowledge article. https://success.salesforce.com/issues_view?id=a1p3A0000008gDzQAI

And a workaround solution here: Unable to get force:inputField or force:outputField to render inside other markup in Lightning Component when used in Lightning Experience

In case that link quits working.. Here is the workaround that Charles Naccio posted that he was using as of Summer '17. I have used this type of workaround myself and I can confirm it does work, though I have not tried it with the Mailing Address fields.

<!-- component setup -->
<aura:handler name="init" value="{!this}" action="{!c.onInit}"/>
<aura:attribute name="newContractLine" type="Contract_Line__c" default="{'sobjectType': 'Contract_Line__c'}" />
<!-- end component setup -->

<!-- workaround for form fields below -->
<force:outputField aura:id="contractType" value="{!v.newContractLine.Type__c}" class="slds-hidden" />
<!-- end workaround -->

<!-- contract line form -->
<lightning:layout horizontalAlign="spread" multipleRows="true">

    <!-- type -->
    <lightning:layoutItem size="6" class="slds-p-horizontal--small">
        <ui:outputText class="slds-form-element--label" value="Type"/>
        <force:inputField aura:id="typeInput" value="{!v.newContractLine.Type__c}"/>
    </lightning:layoutItem>
    <!-- end type -->

</lightning:layout>
<!-- end contract line form -->
  • 2
    Thank you. Unfortunately when I use force:inputField I don't get the compound field labels, nor the State/Country picklists. – Mossi2 Jul 19 '17 at 18:51
  • I have found picklist fields in general to not play well out of the box. I wrote my own picklist component that pulls the describe for the field and populates the values dynamically. It is reusable and works with multipicklists as well. – JRiffe Jul 19 '17 at 19:03

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.