Tip of the week # 210 : Lightning Input Address with Autocomplete

Lightning Input Address with Autocomplete
Description : In Lightning Web Components (LWC), A lightning-input-address component with Autocomplete.(Powered By Google)Code snapshot is following :
-
HTML File
-
JavaScript:
import { LightningElement,api } from 'lwc'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; export default class AddressLwc extends LightningElement { @api recordId; @api objectAPIName='Contact'; strStreet; strCity; strState; strCountry; strPostalCode; handleSuccess( event ) { this.dispatchEvent( new ShowToastEvent({ title: 'Successful Record Update', message: 'Record Updated Surccessfully!!!', variant: 'success' })); } handleSubmit(event){ let fields = event.detail.fields; event.preventDefault(); if ( this.objectAPIName === 'Contact') { fields.MailingStreet = this.strStreet; fields.MailingCity = this.strCity; fields.MailingState = this.strState; fields.MailingCountry = this.strCountry; fields.MailingPostalCode = this.strPostalCode; } this.template.querySelector('lightning-record-edit-form').submit( fields ); } addressInputChange( event ) { this.strStreet = event.target.street; this.strCity = event.target.city; this.strState = event.target.province; this.strCountry = event.target.country; this.strPostalCode = event.target.postalCode; } } -
XML.
63.0 true lightning__RecordPage -
Note : If you are used custom object then you have to enbaled Address field for Custom Object. You are need below step for Google searching.
Autocomplete Addresses
Happy Sharing...
Everyone has their own favorites, so please feel free to share with yours contacts and comments below for any type of help!Use below Chrome Extension for Productivity and share your feedback. Download Link : https://chromewebstore.google.com/detail/quick-shortcuts/ldodfklenhficdgllchmlcldbpeidifp?utm_source=ext_app_menu
Comments
Post a Comment