commit
6f8455f220
2 changed files with 21 additions and 13 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
<label :for="inputId" :aria-label="questionText" class="form-label" v-html="labelText"></label>
|
<label :for="inputId" :aria-label="questionText" class="form-label" v-html="labelText"></label>
|
||||||
<!-- See https://stackoverflow.com/a/30976223 for information about "do-not-autofill" -->
|
<!-- See https://stackoverflow.com/a/30976223 for information about "do-not-autofill" -->
|
||||||
<input
|
<input
|
||||||
v-model="value"
|
v-model.trim="value"
|
||||||
v-maska="mask"
|
v-maska="mask"
|
||||||
:type="type"
|
:type="type"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
|
|
@ -71,7 +71,7 @@ export default {
|
||||||
const fieldOptions = {
|
const fieldOptions = {
|
||||||
type: "text",
|
type: "text",
|
||||||
value: modelValue,
|
value: modelValue,
|
||||||
initialValue: initialValue
|
initialValue: initialValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,8 @@ export default ({
|
||||||
alertCopyVerificationWarning: "",
|
alertCopyVerificationWarning: "",
|
||||||
alertHeadlineNoMatchWarning: "",
|
alertHeadlineNoMatchWarning: "",
|
||||||
alertCopyNoMatchWarning: "",
|
alertCopyNoMatchWarning: "",
|
||||||
|
autocomplete: {},
|
||||||
|
autocompleteListener: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
@ -165,7 +167,7 @@ export default ({
|
||||||
this.$loadScript(`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places`)
|
this.$loadScript(`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places`)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Script is loaded, initialize the autocomplete textbox
|
// Script is loaded, initialize the autocomplete textbox
|
||||||
const autocomplete = new window.google.maps.places.Autocomplete(
|
self.autocomplete = new window.google.maps.places.Autocomplete(
|
||||||
addressField1,
|
addressField1,
|
||||||
{
|
{
|
||||||
componentRestrictions: { country: ["us"] },
|
componentRestrictions: { country: ["us"] },
|
||||||
|
|
@ -175,7 +177,7 @@ export default ({
|
||||||
);
|
);
|
||||||
|
|
||||||
// Standard place_changed event handling
|
// Standard place_changed event handling
|
||||||
const autocompleteListener = window.google.maps.event.addListener(autocomplete, 'place_changed', fillInAddress);
|
self.autocompleteListener = window.google.maps.event.addListener(this.autocomplete, 'place_changed', fillInAddress);
|
||||||
|
|
||||||
// Wrapping the addressField1 element in the Google Address Autocomplete object
|
// Wrapping the addressField1 element in the Google Address Autocomplete object
|
||||||
// will cause "autocomplete='off'" which Chrome completely ignores. This event
|
// will cause "autocomplete='off'" which Chrome completely ignores. This event
|
||||||
|
|
@ -221,12 +223,10 @@ export default ({
|
||||||
|
|
||||||
function fillInAddress(place) {
|
function fillInAddress(place) {
|
||||||
if (!place) {
|
if (!place) {
|
||||||
place = autocomplete.getPlace();
|
place = self.autocomplete.getPlace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (place && place.address_components) {
|
if (place && place.address_components) {
|
||||||
self.showAddressFields = true;
|
|
||||||
|
|
||||||
for (const component of place.address_components) {
|
for (const component of place.address_components) {
|
||||||
const componentType = component.types[0];
|
const componentType = component.types[0];
|
||||||
|
|
||||||
|
|
@ -257,18 +257,15 @@ export default ({
|
||||||
|
|
||||||
self.displayVerificationWarning = false;
|
self.displayVerificationWarning = false;
|
||||||
self.displayNoMatchWarning = false;
|
self.displayNoMatchWarning = false;
|
||||||
|
|
||||||
|
self.showAddressFields = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.displayVerificationWarning = true;
|
self.displayVerificationWarning = true;
|
||||||
self.displayNoMatchWarning = false;
|
self.displayNoMatchWarning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// after showing the address fields, disable the address autocomplete
|
|
||||||
window.google.maps.event.removeListener(autocompleteListener);
|
|
||||||
window.google.maps.event.clearInstanceListeners(autocomplete);
|
|
||||||
addressField1.onchange = null;
|
|
||||||
const pacContainer = document.querySelector(".pac-container");
|
|
||||||
pacContainer.remove();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -296,6 +293,17 @@ export default ({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
|
},
|
||||||
|
showAddressFields: {
|
||||||
|
handler(newValue) {
|
||||||
|
// after showing the address fields, disable the address autocomplete
|
||||||
|
window.google.maps.event.removeListener(this.autocompleteListener);
|
||||||
|
window.google.maps.event.clearInstanceListeners(this.autocomplete);
|
||||||
|
const addressField1 = document.getElementById("autocomplete");
|
||||||
|
addressField1.onchange = null;
|
||||||
|
const pacContainer = document.querySelector(".pac-container");
|
||||||
|
pacContainer.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue