fix: Input form adding issue

This commit is contained in:
2025-11-09 18:20:40 +01:00
parent 7407b66d83
commit 7ad2134c5e
3 changed files with 44 additions and 37 deletions

View File

@@ -18,11 +18,7 @@
/> />
<div class="flex gap-2 justify-between mt-4"> <div class="flex gap-2 justify-between mt-4">
<UButton <UButton leading-icon="i-lucide-arrow-left" :disabled="!stepper?.hasPrev" @click="handleNavigate('backward')">
leading-icon="i-lucide-arrow-left"
:disabled="!stepper?.hasPrev"
@click="handleNavigate('backward')"
>
Prev Prev
</UButton> </UButton>
@@ -36,19 +32,10 @@
</UButton> </UButton>
<div v-if="!stepper?.hasNext" class="flex flex-wrap items-center gap-1.5"> <div v-if="!stepper?.hasNext" class="flex flex-wrap items-center gap-1.5">
<UButton <UButton trailing-icon="i-lucide-save" :disabled="disabled" variant="outline" @click="emit('save')">
trailing-icon="i-lucide-save"
:disabled="disabled"
variant="outline"
@click="emit('save')"
>
Save Save
</UButton> </UButton>
<UButton <UButton trailing-icon="i-lucide-send-horizontal" :disabled="disabled" @click="emit('submit')">
trailing-icon="i-lucide-send-horizontal"
:disabled="disabled"
@click="emit('submit')"
>
Submit Submit
</UButton> </UButton>
</div> </div>
@@ -58,7 +45,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import type { FormElementSectionDto } from '~~/.api-client' import type { ApplicationFormDto, FormElementSectionDto } from '~~/.api-client'
const props = defineProps<{ const props = defineProps<{
formElementSections: FormElementSectionDto[] formElementSections: FormElementSectionDto[]
@@ -70,7 +57,7 @@ const props = defineProps<{
const emit = defineEmits<{ const emit = defineEmits<{
save: [] save: []
submit: [] submit: []
'add-input-form': [position: number] 'add-input-form': [updatedForm: ApplicationFormDto | undefined]
navigate: [{ direction: 'forward' | 'backward'; index: number }] navigate: [{ direction: 'forward' | 'backward'; index: number }]
}>() }>()
@@ -78,10 +65,7 @@ const { stepper, activeStepperItemIndex, stepperItems, currentFormElementSection
computed(() => props.formElementSections) computed(() => props.formElementSections)
) )
const { addInputFormToApplicationForm } = useFormElementManagement( const { addInputFormToApplicationForm } = useFormElementManagement(currentFormElementSection, props.applicationFormId)
currentFormElementSection,
props.applicationFormId
)
onMounted(() => { onMounted(() => {
if (props.initialSectionIndex !== undefined) { if (props.initialSectionIndex !== undefined) {
@@ -90,12 +74,8 @@ onMounted(() => {
}) })
async function handleAddInputForm(position: number) { async function handleAddInputForm(position: number) {
if (props.applicationFormId) { const updatedForm = await addInputFormToApplicationForm(position)
await addInputFormToApplicationForm(position) emit('add-input-form', updatedForm)
} else {
await addInputFormToApplicationForm(position)
}
emit('add-input-form', position)
} }
async function handleNavigate(direction: 'forward' | 'backward') { async function handleNavigate(direction: 'forward' | 'backward') {
@@ -103,4 +83,3 @@ async function handleNavigate(direction: 'forward' | 'backward') {
emit('navigate', { direction, index: activeStepperItemIndex.value }) emit('navigate', { direction, index: activeStepperItemIndex.value })
} }
</script> </script>

View File

@@ -29,6 +29,7 @@
@save="onSave" @save="onSave"
@submit="onSubmit" @submit="onSubmit"
@navigate="handleNavigate" @navigate="handleNavigate"
@add-input-form="handleAddInputForm"
/> />
</div> </div>
</template> </template>
@@ -36,7 +37,12 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ComplianceStatus, type FormElementDto, type FormElementSectionDto } from '~~/.api-client' import {
ComplianceStatus,
type ApplicationFormDto,
type FormElementDto,
type FormElementSectionDto
} from '~~/.api-client'
import type { FormElementId } from '~~/types/formElement' import type { FormElementId } from '~~/types/formElement'
import { useApplicationFormValidator } from '~/composables/useApplicationFormValidator' import { useApplicationFormValidator } from '~/composables/useApplicationFormValidator'
import { useUserStore } from '~~/stores/useUserStore' import { useUserStore } from '~~/stores/useUserStore'
@@ -111,4 +117,10 @@ async function onSubmit() {
async function handleNavigate({ index }: { direction: 'forward' | 'backward'; index: number }) { async function handleNavigate({ index }: { direction: 'forward' | 'backward'; index: number }) {
await navigateTo(`/application-forms/${applicationFormId}/${index}`) await navigateTo(`/application-forms/${applicationFormId}/${index}`)
} }
function handleAddInputForm(updatedForm: ApplicationFormDto | undefined) {
if (updatedForm) {
updateApplicationForm(updatedForm)
}
}
</script> </script>

View File

@@ -25,6 +25,7 @@
:form-element-sections="applicationFormTemplate.formElementSections" :form-element-sections="applicationFormTemplate.formElementSections"
@save="onSave" @save="onSave"
@submit="onSubmit" @submit="onSubmit"
@add-input-form="handleAddInputForm"
> >
<UFormField label="Name" class="mb-4"> <UFormField label="Name" class="mb-4">
<UInput v-model="applicationFormTemplate.name" /> <UInput v-model="applicationFormTemplate.name" />
@@ -37,7 +38,12 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ComplianceStatus, type PagedApplicationFormDto } from '~~/.api-client' import {
ComplianceStatus,
type FormElementDto,
type FormElementSectionDto,
type PagedApplicationFormDto
} from '~~/.api-client'
import { useApplicationFormValidator } from '~/composables/useApplicationFormValidator' import { useApplicationFormValidator } from '~/composables/useApplicationFormValidator'
import type { FormElementId } from '~~/types/formElement' import type { FormElementId } from '~~/types/formElement'
import { useUserStore } from '~~/stores/useUserStore' import { useUserStore } from '~~/stores/useUserStore'
@@ -71,12 +77,16 @@ const validationMap = ref<Map<FormElementId, ComplianceStatus> | undefined>()
const validationStatus = ref<ComplianceStatus>(ComplianceStatus.NonCritical) const validationStatus = ref<ComplianceStatus>(ComplianceStatus.NonCritical)
const allFormElements = computed(() => { const allFormElements = computed(() => {
return applicationFormTemplate.value?.formElementSections?.flatMap((section) => section.formElements) ?? [] return (
applicationFormTemplate.value?.formElementSections?.flatMap(
(section: FormElementSectionDto) => section.formElements
) ?? []
)
}) })
watch( watch(
() => allFormElements.value, () => allFormElements.value,
(updatedFormElements) => { (updatedFormElements: FormElementDto[]) => {
validationMap.value = validateFormElements(updatedFormElements) validationMap.value = validateFormElements(updatedFormElements)
validationStatus.value = getHighestComplianceStatus() validationStatus.value = getHighestComplianceStatus()
}, },
@@ -99,6 +109,12 @@ async function onSubmit() {
} }
} }
function handleAddInputForm() {
// In create mode (no applicationFormId), addInputFormToApplicationForm returns undefined
// The form element is added locally to the template sections, which are reactive
// No action needed here
}
async function prepareAndCreateApplicationForm() { async function prepareAndCreateApplicationForm() {
if (!applicationFormTemplate.value) { if (!applicationFormTemplate.value) {
console.error('Application form data is undefined') console.error('Application form data is undefined')