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 ?– RaoJul 18, 2017 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 ManenteJul 18, 2017 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.– Mossi2Jul 19, 2017 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?– RaoJul 19, 2017 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.– Mossi2Jul 19, 2017 at 18:49
2 Answers
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
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 -->
-
2Thank you. Unfortunately when I use force:inputField I don't get the compound field labels, nor the State/Country picklists.– Mossi2Jul 19, 2017 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.– JRiffeJul 19, 2017 at 19:03