Added programmatic watch for address model when an address is not found

This commit is contained in:
Leah Schumann 2022-12-13 16:27:43 -05:00
parent 0b6eed45ac
commit 2bc14c5a31

View file

@ -111,8 +111,9 @@ export default {
alertHeadlineNoMatchWarning: "", alertHeadlineNoMatchWarning: "",
alertCopyNoMatchWarning: "", alertCopyNoMatchWarning: "",
matchingIndirectly: false, matchingIndirectly: false,
matchFound: false, matchFound: null, // null = no attempted match, true = match was found, false = match was not found
enterPressed: false, enterPressed: false,
unwatchAddress: null // handle to allow us to only deep watch the address model when a match was not found
}; };
}, },
computed: { computed: {
@ -284,13 +285,8 @@ export default {
} }
); );
} else { } else {
// If there are no addresses found for the input then display empty address fields and warnings // No addresses found for the input
self.addressModel.city = ""; self.matchFound = false;
self.addressModel.state = "";
self.addressModel.zipCode = "";
self.showAddressFields = true;
self.displayVerificationWarning = false;
self.displayNoMatchWarning = true;
} }
} }
}); });
@ -363,8 +359,26 @@ export default {
watch: { watch: {
matchFound: { matchFound: {
handler(newValue) { handler(newValue) {
if (newValue) { if (newValue === null) {
this.displayNoMatchWarning = false; this.displayNoMatchWarning = false;
this.unwatchAddress();
return;
}
if (!newValue) {
this.displayNoMatchWarning = true;
this.addressModel.city = "";
this.addressModel.state = "";
this.addressModel.zipCode = "";
this.showAddressFields = true;
this.displayVerificationWarning = false;
// Only deep watch the Address Model after a failed match
this.unwatchAddress = this.$watch("addressModel", (newAddress) => {
// When the address model changes reset to "no attempted match"
this.matchFound = null;
}, { deep: true });
} }
}, },
}, },