fix: refs #8217 update FormModel to use toRef for mapper and improve data handling
This commit is contained in:
parent
a37dacbf57
commit
7ebbb5da9a
|
@ -1,6 +1,15 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { onMounted, onUnmounted, computed, ref, watch, nextTick, useAttrs } from 'vue';
|
import {
|
||||||
|
onMounted,
|
||||||
|
onUnmounted,
|
||||||
|
computed,
|
||||||
|
ref,
|
||||||
|
watch,
|
||||||
|
nextTick,
|
||||||
|
useAttrs,
|
||||||
|
toRef,
|
||||||
|
} from 'vue';
|
||||||
import { onBeforeRouteLeave, useRouter, useRoute } from 'vue-router';
|
import { onBeforeRouteLeave, useRouter, useRoute } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
|
@ -140,6 +149,7 @@ const submitForm = async (evt) => {
|
||||||
await save(evt);
|
await save(evt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const mapper = toRef($props, 'mapper');
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
nextTick(() => (componentIsRendered.value = true));
|
nextTick(() => (componentIsRendered.value = true));
|
||||||
|
@ -247,7 +257,9 @@ async function create() {
|
||||||
|
|
||||||
async function update() {
|
async function update() {
|
||||||
formData.value = trimData(formData.value);
|
formData.value = trimData(formData.value);
|
||||||
const body = $props.mapper(originalData.value, formData.value);
|
const body = mapper.value
|
||||||
|
? mapper.value(originalData.value, formData.value)
|
||||||
|
: formData.value;
|
||||||
const url = $props.urlUpdate || $props.url || arrayData.store.url;
|
const url = $props.urlUpdate || $props.url || arrayData.store.url;
|
||||||
const response = await Promise.resolve(
|
const response = await Promise.resolve(
|
||||||
$props.saveFn ? $props.saveFn(body) : axios.patch(url, body),
|
$props.saveFn ? $props.saveFn(body) : axios.patch(url, body),
|
||||||
|
|
|
@ -39,6 +39,7 @@ const entityId = computed(() => {
|
||||||
where: { itemFk: entityId },
|
where: { itemFk: entityId },
|
||||||
}"
|
}"
|
||||||
@on-fetch="(data) => (itemBotanicalsForm = data)"
|
@on-fetch="(data) => (itemBotanicalsForm = data)"
|
||||||
|
:mapper="(_, data) => data"
|
||||||
>
|
>
|
||||||
<template #form="{ data }">
|
<template #form="{ data }">
|
||||||
<VnRow>
|
<VnRow>
|
||||||
|
|
Loading…
Reference in New Issue