diff --git a/components/story/create/storyForm.vue b/components/story/create/storyForm.vue index 22d56a8..46c9d08 100644 --- a/components/story/create/storyForm.vue +++ b/components/story/create/storyForm.vue @@ -13,14 +13,17 @@ import icon from "~/components/icon.vue"; const props = defineProps<{ - data: FormStory; canDraft?: boolean; endpoint: string; endpointMethod: "put" | "post"; submitText?: string; }>(); + const dc = defaultChapter; + // data: FormStory; + const data = defineModel("data", { + required: true, + }); let drag = false; - let acData = ref(props.data); const expandos = ref([]); function logSubmit(values, actions) { @@ -36,7 +39,7 @@ otherBtnInvoked.value = false; await autoSave(values); } else { - await useApiFetch(`/story/new`, { + const { data: dat } = await useApiFetch(`/story/new`, { method: "post", body: values, }); @@ -48,10 +51,10 @@ function inval({ values, errors, results }) { logSubmit(values, undefined); } - const { values, setFieldValue, handleSubmit } = useForm({ + const { values, setFieldValue, handleSubmit } = useForm({ keepValuesOnUnmount: true, validationSchema: storySchema, - initialValues: props.data, + initialValues: data.value, }); const subCb = handleSubmit(onSubmit); @@ -92,7 +95,7 @@ if (e.moved) { // log.debug(e.moved); move(e.moved.oldIndex, e.moved.newIndex); - acData.chapters = lmove(acData.chapters, e.moved.oldIndex, e.moved.newIndex); + data.chapters = lmove(data.chapters, e.moved.oldIndex, e.moved.newIndex); // log.debug(toRaw(acData.chapters.map((a) => toRaw(a)))); } } @@ -109,7 +112,7 @@ let localFields = toRaw(fields); // log.debug(`${index} | ${element.index}`); // log.debug('fields->', localFields); - acData.chapters.splice(index, 1); + data.chapters.splice(index, 1); remove(index); // todo renumber // renumber() @@ -148,7 +151,7 @@ }); // log.debug('nc->', newChapter); push(newChapter); - acData.chapters.push(newChapter); + data.chapters.push(newChapter); } " > diff --git a/pages/new-story.vue b/pages/new-story.vue index eacce32..06403ba 100644 --- a/pages/new-story.vue +++ b/pages/new-story.vue @@ -1,6 +1,7 @@