From c6477af4938976b2d2c9b079ebf6237be0cbea1b Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 23 May 2024 09:29:50 +0200 Subject: [PATCH] fix: refs #6942 formModel watch changes & invoiceInCreate --- src/components/FormModel.vue | 19 +++++++++++-------- src/pages/InvoiceIn/InvoiceInCreate.vue | 13 +++++++------ src/router/modules/invoiceIn.js | 6 +++--- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 79407dcb4..f5cfdd734 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -109,7 +109,7 @@ const defaultButtons = computed(() => ({ })); onMounted(async () => { - originalData.value = $props.formInitialData; + originalData.value = JSON.parse(JSON.stringify($props.formInitialData ?? {})); nextTick(() => (componentIsRendered.value = true)); @@ -124,7 +124,9 @@ onMounted(async () => { () => formData.value, (newVal, oldVal) => { if (!oldVal) return; - hasChanges.value = !isResetting.value && newVal; + hasChanges.value = + !isResetting.value && + JSON.stringify(newVal) !== JSON.stringify(originalData.value); isResetting.value = false; }, { deep: true } @@ -145,6 +147,7 @@ watch(formUrl, async () => { }); onBeforeRouteLeave((to, from, next) => { + console.log('entro aqui antes'); if (hasChanges.value && $props.observeFormChanges) quasar.dialog({ component: VnConfirm, @@ -177,7 +180,7 @@ async function fetch() { } } -async function save() { +async function save(emit = true) { if ($props.observeFormChanges && !hasChanges.value) return notify('globals.noChanges', 'negative'); @@ -194,18 +197,18 @@ async function save() { if ($props.urlCreate) notify('globals.dataCreated', 'positive'); - updateAndEmit(response?.data, 'onDataSaved'); hasChanges.value = false; + isLoading.value = false; + + if (emit) updateAndEmit(response?.data, 'onDataSaved'); } catch (err) { console.error(err); notify('errors.writeRequest', 'negative'); - } finally { - isLoading.value = false; } } async function saveAndGo() { - await save(); + await save(null); push({ path: $props.goTo }); } @@ -240,7 +243,7 @@ function updateAndEmit(val, evt) { emit(evt, state.get($props.model)); } -defineExpose({ save, isLoading, hasChanges }); +defineExpose({ save, saveAndGo, isLoading, hasChanges });