diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index d2f346382..54c41f77e 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -111,7 +111,7 @@ const isLoading = ref(false); // Si elegimos observar los cambios del form significa que inicialmente las actions estaran deshabilitadas const isResetting = ref(false); const hasChanges = ref(!$props.observeFormChanges); -const originalData = computed(() => state.get(modelValue)); +const originalData = computed(() => state.get(modelValue) ?? {}); const formData = ref(); const defaultButtons = computed(() => ({ save: { diff --git a/src/filters/getDifferences.js b/src/filters/getDifferences.js index 54a82420b..5a1c42b97 100644 --- a/src/filters/getDifferences.js +++ b/src/filters/getDifferences.js @@ -1,16 +1,10 @@ export default function getDifferences(initialData, formData) { const differences = {}; - delete initialData.$index; - delete formData.$index; - + if (initialData) delete initialData.$index; + if (formData) delete formData.$index; for (const key in formData) { if (formData.hasOwnProperty(key)) { - if ( - !initialData || - !initialData.hasOwnProperty(key) || - formData[key] !== initialData[key] - ) { - //AƱadir la diferencia solo si existe initialData + if (!initialData.hasOwnProperty(key) || formData[key] !== initialData[key]) { if (initialData) { differences[key] = formData[key]; }