From f765cde1e50e92e0da543794374b14264855fc0a Mon Sep 17 00:00:00 2001 From: Artur Tagisow <5359825+sethidden@users.noreply.github.com> Date: Tue, 21 Jun 2022 08:34:52 +0200 Subject: [PATCH] fix: user addresses - reset region if changing country (#1140) --- .../MyAccount/AddressesDetails/AddressForm.vue | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/theme/modules/customer/pages/MyAccount/AddressesDetails/AddressForm.vue b/packages/theme/modules/customer/pages/MyAccount/AddressesDetails/AddressForm.vue index b9e6b6f60..f050cd204 100644 --- a/packages/theme/modules/customer/pages/MyAccount/AddressesDetails/AddressForm.vue +++ b/packages/theme/modules/customer/pages/MyAccount/AddressesDetails/AddressForm.vue @@ -281,18 +281,21 @@ export default defineComponent({ setup(props, { emit }) { const { load: loadCountries, search: searchCountry } = useCountrySearch(); + const form = ref(null); + const countries = ref([]); const countriesList = computed(() => addressGetter.countriesList(countries.value)); - const country = ref(null); + const regionInformation = computed(() => addressGetter.regionList(country.value)); + const updateCountry = async (params: UseCountrySearchParams) => { country.value = await searchCountry(params); + form.value.region = { + // let region SfSelect know it should display initial state + ...(regionInformation.value.length > 0 ? { region_id: null } : {}), + }; }; - const regionInformation = computed(() => addressGetter.regionList(country.value)); - - const form = ref(null); - watch(() => props.address, () => { form.value = { apartment: props.address.apartment, @@ -329,7 +332,7 @@ export default defineComponent({ onBeforeMount(async () => { countries.value = await loadCountries(); if (props.address.country_code) { - await updateCountry({ id: props.address.country_code }); + country.value = await searchCountry({ id: props.address.country_code }); } });