diff --git a/src/components/CreateNewPostcodeForm.vue b/src/components/CreateNewPostcodeForm.vue
index 4c44d29e2..664016325 100644
--- a/src/components/CreateNewPostcodeForm.vue
+++ b/src/components/CreateNewPostcodeForm.vue
@@ -1,5 +1,5 @@
(provincesOptions = data)"
+ @on-fetch="handleProvinces"
auto-load
url="Provinces/location"
/>
(countriesOptions = data)"
+ ref="townsFetchDataRef"
+ @on-fetch="handleTowns"
auto-load
- url="Countries"
+ url="Towns/location"
/>
+
setTown(value, data)"
v-model="data.townFk"
+ :options="townsOptions"
option-label="name"
option-value="id"
:rules="validate('postcode.city')"
@@ -132,6 +177,7 @@ async function setProvince(id, data) {
setProvince(value, data)"
v-model="data.provinceFk"
/>
diff --git a/src/components/VnSelectProvince.vue b/src/components/VnSelectProvince.vue
index 2f08db611..3f8388c69 100644
--- a/src/components/VnSelectProvince.vue
+++ b/src/components/VnSelectProvince.vue
@@ -10,7 +10,13 @@ import CreateNewProvinceForm from './CreateNewProvinceForm.vue';
const emit = defineEmits(['onProvinceCreated']);
const provinceFk = defineModel({ type: Number });
watch(provinceFk, async () => await provincesFetchDataRef.value.fetch());
-
+const $props = defineProps({
+ countryFk: {
+ type: Number,
+ required: false,
+ default: null,
+ },
+});
const { validate } = useValidator();
const { t } = useI18n();
@@ -18,17 +24,31 @@ const provincesOptions = ref();
const provincesFetchDataRef = ref();
async function onProvinceCreated(_, data) {
- await provincesFetchDataRef.value.fetch();
+ await provincesFetchDataRef.value.fetch({ where: { countryFk: $props.countryFk } });
provinceFk.value = data.id;
emit('onProvinceCreated', data);
}
+watch(
+ () => $props.countryFk,
+ async (newProvinceFk) => {
+ if (newProvinceFk) {
+ // Assuming there's a townsFetchDataRef similar to provincesFetchDataRef
+ await provincesFetchDataRef.value.fetch({
+ where: { countryFk: newProvinceFk },
+ });
+ }
+ }
+);
+async function handleProvinces(data) {
+ provincesOptions.value = data;
+}
(provincesOptions = data)"
+ @on-fetch="handleProvinces"
auto-load
url="Provinces"
/>