diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 5a59f301e..a92ba29ee 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -134,7 +134,8 @@ onMounted(async () => { if (!$props.formInitialData) { if ($props.autoLoad && $props.url) await fetch(); - else if (arrayData.store.data) updateAndEmit('onFetch', arrayData.store.data); + else if (arrayData.store.data) + updateAndEmit('onFetch', { val: arrayData.store.data }); } if ($props.observeFormChanges) { watch( @@ -154,7 +155,7 @@ onMounted(async () => { if (!$props.url) watch( () => arrayData.store.data, - (val) => updateAndEmit('onFetch', val), + (val) => updateAndEmit('onFetch', { val }), ); watch( @@ -200,7 +201,7 @@ async function fetch() { }); if (Array.isArray(data)) data = data[0] ?? {}; - updateAndEmit('onFetch', data); + updateAndEmit('onFetch', { val: data }); } catch (e) { state.set(modelValue, {}); throw e; @@ -228,7 +229,11 @@ async function save(prevent = false) { if ($props.urlCreate) notify('globals.dataCreated', 'positive'); - updateAndEmit('onDataSaved', formData.value, response?.data); + updateAndEmit('onDataSaved', { + val: formData.value, + res: response?.data, + old: originalData.value, + }); if ($props.reload) await arrayData.fetch({}); hasChanges.value = false; } finally { @@ -242,8 +247,7 @@ async function saveAndGo() { } function reset() { - formData.value = JSON.parse(JSON.stringify(originalData.value)); - updateAndEmit('onFetch', originalData.value); + updateAndEmit('onFetch', { val: originalData.value }); if ($props.observeFormChanges) { hasChanges.value = false; isResetting.value = true; @@ -265,11 +269,11 @@ function filter(value, update, filterOptions) { ); } -function updateAndEmit(evt, val, res) { +function updateAndEmit(evt, { val, res, old } = { val: null, res: null, old: null }) { state.set(modelValue, val); if (!$props.url) arrayData.store.data = val; - emit(evt, state.get(modelValue), res); + emit(evt, state.get(modelValue), res, old); } function trimData(data) { diff --git a/src/components/TicketProblems.vue b/src/components/TicketProblems.vue index a24735a5f..17d9602af 100644 --- a/src/components/TicketProblems.vue +++ b/src/components/TicketProblems.vue @@ -1,4 +1,6 @@