diff --git a/src/components/common/VnLocation.vue b/src/components/common/VnLocation.vue index f58222187..3ede24274 100644 --- a/src/components/common/VnLocation.vue +++ b/src/components/common/VnLocation.vue @@ -2,7 +2,7 @@ import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue'; import VnSelectDialog from 'components/common/VnSelectDialog.vue'; import { useI18n } from 'vue-i18n'; -import { computed } from 'vue'; +import { ref, watch } from 'vue'; import { useAttrs } from 'vue'; import { useRequired } from 'src/composables/useRequired'; const { t } = useI18n(); @@ -16,6 +16,14 @@ const props = defineProps({ }, }); +watch( + () => props.location, + (newValue) => { + if (!modelValue.value) return; + modelValue.value = formatLocation(newValue) ?? null; + } +); + const mixinRules = [requiredFieldRule]; const locationProperties = [ 'postcode', @@ -43,9 +51,7 @@ const formatLocation = (obj, properties = locationProperties) => { return filteredParts.join(', '); }; -const modelValue = computed(() => - props.location ? formatLocation(props.location, locationProperties) : null -); +const modelValue = ref(props.location ? formatLocation(props.location) : null); function showLabel(data) { const dataProperties = [