fix: Input form adding issue
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<template>
|
||||
<div class="flex flex-col w-full lg:max-w-4xl mx-auto">
|
||||
<slot />
|
||||
|
||||
|
||||
<UStepper ref="stepper" v-model="activeStepperItemIndex" :items="stepperItems" class="w-full" />
|
||||
|
||||
|
||||
<h1 v-if="currentFormElementSection?.title" class="text-xl text-pretty font-bold text-highlighted">
|
||||
{{ currentFormElementSection.title }}
|
||||
</h1>
|
||||
|
||||
|
||||
<UCard variant="subtle">
|
||||
<FormEngine
|
||||
v-if="currentFormElementSection?.formElements"
|
||||
@@ -16,13 +16,9 @@
|
||||
:disabled="disabled"
|
||||
@add:input-form="handleAddInputForm"
|
||||
/>
|
||||
|
||||
|
||||
<div class="flex gap-2 justify-between mt-4">
|
||||
<UButton
|
||||
leading-icon="i-lucide-arrow-left"
|
||||
:disabled="!stepper?.hasPrev"
|
||||
@click="handleNavigate('backward')"
|
||||
>
|
||||
<UButton leading-icon="i-lucide-arrow-left" :disabled="!stepper?.hasPrev" @click="handleNavigate('backward')">
|
||||
Prev
|
||||
</UButton>
|
||||
|
||||
@@ -36,19 +32,10 @@
|
||||
</UButton>
|
||||
|
||||
<div v-if="!stepper?.hasNext" class="flex flex-wrap items-center gap-1.5">
|
||||
<UButton
|
||||
trailing-icon="i-lucide-save"
|
||||
:disabled="disabled"
|
||||
variant="outline"
|
||||
@click="emit('save')"
|
||||
>
|
||||
<UButton trailing-icon="i-lucide-save" :disabled="disabled" variant="outline" @click="emit('save')">
|
||||
Save
|
||||
</UButton>
|
||||
<UButton
|
||||
trailing-icon="i-lucide-send-horizontal"
|
||||
:disabled="disabled"
|
||||
@click="emit('submit')"
|
||||
>
|
||||
<UButton trailing-icon="i-lucide-send-horizontal" :disabled="disabled" @click="emit('submit')">
|
||||
Submit
|
||||
</UButton>
|
||||
</div>
|
||||
@@ -58,7 +45,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { FormElementSectionDto } from '~~/.api-client'
|
||||
import type { ApplicationFormDto, FormElementSectionDto } from '~~/.api-client'
|
||||
|
||||
const props = defineProps<{
|
||||
formElementSections: FormElementSectionDto[]
|
||||
@@ -70,7 +57,7 @@ const props = defineProps<{
|
||||
const emit = defineEmits<{
|
||||
save: []
|
||||
submit: []
|
||||
'add-input-form': [position: number]
|
||||
'add-input-form': [updatedForm: ApplicationFormDto | undefined]
|
||||
navigate: [{ direction: 'forward' | 'backward'; index: number }]
|
||||
}>()
|
||||
|
||||
@@ -78,10 +65,7 @@ const { stepper, activeStepperItemIndex, stepperItems, currentFormElementSection
|
||||
computed(() => props.formElementSections)
|
||||
)
|
||||
|
||||
const { addInputFormToApplicationForm } = useFormElementManagement(
|
||||
currentFormElementSection,
|
||||
props.applicationFormId
|
||||
)
|
||||
const { addInputFormToApplicationForm } = useFormElementManagement(currentFormElementSection, props.applicationFormId)
|
||||
|
||||
onMounted(() => {
|
||||
if (props.initialSectionIndex !== undefined) {
|
||||
@@ -90,12 +74,8 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
async function handleAddInputForm(position: number) {
|
||||
if (props.applicationFormId) {
|
||||
await addInputFormToApplicationForm(position)
|
||||
} else {
|
||||
await addInputFormToApplicationForm(position)
|
||||
}
|
||||
emit('add-input-form', position)
|
||||
const updatedForm = await addInputFormToApplicationForm(position)
|
||||
emit('add-input-form', updatedForm)
|
||||
}
|
||||
|
||||
async function handleNavigate(direction: 'forward' | 'backward') {
|
||||
@@ -103,4 +83,3 @@ async function handleNavigate(direction: 'forward' | 'backward') {
|
||||
emit('navigate', { direction, index: activeStepperItemIndex.value })
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user