2

I am using the lightning:inputAddress on an aura lightning component with showAddressLookup="true". The user can start typing an address in the search field and it will auto-complete the address.

This all works great but if the user wants to enter a new address, I wrote a js method to reset the component values street, city, state, etc, but I cannot reset the address search field. There is nothing about this in the Salesforce documentation here

lightning:inputAddress component

Here's the component:

   <lightning:inputAddress 
    aura:id="newServiceAddressInput" addressLabel="Address"
    streetLabel="Street"
    cityLabel="City"
    countryLabel="Country"
    provinceLabel="State"
    postalCodeLabel="PostalCode"
    country="US"                               
    required="true"
    fieldLevelHelp="Start typing an address below to search Google addresses, or enter address details yourself."
    showAddressLookup="true"
    onchange="{!c.handleInputAddressChange}"
    addressLookupPlaceholder="Search Google addresses..."/>

and the js:

var addressInput = component.find('newServiceAddressInput');
addressInput.set("v.street","");
addressInput.set("v.city","");
addressInput.set("v.province","");
addressInput.set("v.postalCode","");
addressInput.set("v.country",""); 

1 Answer 1

2

I also faced this issue before. I couldn't find any official solution. But I found one workaround to fix the issue. First you need to set the showAddressLookup to false and then to true after some delay. I used window.setTimeout for this delay. There is a slight flicker but it will solve your purpose.

({
    handleClick : function(component) {
        var addressInput = component.find('newServiceAddressInput');
        addressInput.set("v.showAddressLookup",false);
        addressInput.set("v.street","");
        addressInput.set("v.city","");
        addressInput.set("v.province","");
        addressInput.set("v.postalCode","");
        addressInput.set("v.country","");
        window.setTimeout(
            $A.getCallback(function() {
                addressInput.set("v.showAddressLookup",true);
            }), 5
        );        
    }
})
2
  • If anyone has a better solution please share.
    – Saroj Bera
    Jul 24, 2022 at 18:18
  • Thank you Saroj! This worked perfectly! Jul 26, 2022 at 18:49

You must log in to answer this question.

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