Skip to content

Instantly share code, notes, and snippets.

@ShariqT
Last active November 19, 2021 05:56
Show Gist options
  • Save ShariqT/c62f0af259a38b1baf00fe9d2178febc to your computer and use it in GitHub Desktop.
Save ShariqT/c62f0af259a38b1baf00fe9d2178febc to your computer and use it in GitHub Desktop.
AddressForm.vue
import { toRefs, ref, onMounted } from "vue";
const props = defineProps({
address: Object,
formId: String
})
const { name, address_line1, address_line2, address_city, address_state, address_zip } = toRefs(props.address)
const subscription = ref();
onMounted(() => {
window.addEventListener("keydown", () => {
if (subscription.value || !window.LobAddressElements) return
subscription.value = window.LobAddressElements.on('elements.us_autocompletion.selection', function (payload) {
if (payload.form.id !== props.formId) return
const { selection: {
primary_line, city, state, zip_code
}
} = payload
address_line1.value = primary_line
address_city.value = city
address_state.value = state
address_zip.value = zip_code
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment