diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index bb5466eff..79407dcb4 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -115,18 +115,16 @@ onMounted(async () => { // Podemos enviarle al form la estructura de data inicial sin necesidad de fetchearla state.set($props.model, $props.formInitialData); - if ($props.autoLoad && !$props.formInitialData && $props.url) await fetch(); - else if (arrayData.store.data) { - state.set($props.model, arrayData.store.data); - emit('onFetch', state.get($props.model)); - } + if ($props.autoLoad && !$props.formInitialData && $props.url) await fetch(); + else if (arrayData.store.data) updateAndEmit(arrayData.store.data, 'onFetch'); if ($props.observeFormChanges) { watch( () => formData.value, - (val) => { - hasChanges.value = !isResetting.value && val; + (newVal, oldVal) => { + if (!oldVal) return; + hasChanges.value = !isResetting.value && newVal; isResetting.value = false; }, { deep: true } @@ -143,7 +141,7 @@ if (!$props.url) watch(formUrl, async () => { originalData.value = null; reset(); - fetch(); + await fetch(); }); onBeforeRouteLeave((to, from, next) => { @@ -161,10 +159,7 @@ onBeforeRouteLeave((to, from, next) => { onUnmounted(() => { // Restauramos los datos originales en el store si se realizaron cambios en el formulario pero no se guardaron, evitando modificaciones errĂ³neas. - if (hasChanges.value) { - state.set($props.model, originalData.value); - return; - } + if (hasChanges.value) return state.set($props.model, originalData.value); if ($props.clearStoreOnUnmount) state.unset($props.model); }); diff --git a/src/components/ui/CardDescriptor.vue b/src/components/ui/CardDescriptor.vue index 570d35e9e..fbf2df813 100644 --- a/src/components/ui/CardDescriptor.vue +++ b/src/components/ui/CardDescriptor.vue @@ -15,10 +15,6 @@ const $props = defineProps({ type: Object, default: null, }, - module: { - type: String, - required: true, - }, title: { type: String, default: '', @@ -29,7 +25,7 @@ const $props = defineProps({ }, dataKey: { type: String, - default: '', + default: null, }, summary: { type: Object, @@ -40,7 +36,7 @@ const $props = defineProps({ const state = useState(); const { t } = useI18n(); const { viewSummary } = useSummaryDialog(); -const arrayData = useArrayData($props.dataKey || $props.module, { +const arrayData = useArrayData($props.dataKey || 'descriptor', { url: $props.url, filter: $props.filter, skip: 0, @@ -51,7 +47,7 @@ const isLoading = ref(false); defineExpose({ getData }); onBeforeMount(async () => { - await getData(); + if (!$props.dataKey) await getData(); watch( () => [$props.url, $props.filter], async () => await getData() @@ -93,7 +89,12 @@ const emit = defineEmits(['onFetch']); {{ t('components.smartCard.openSummary') }} - +