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

@@ -25,6 +25,7 @@
:form-element-sections="applicationFormTemplate.formElementSections"
@save="onSave"
@submit="onSubmit"
@add-input-form="handleAddInputForm"
>
<UFormField label="Name" class="mb-4">
<UInput v-model="applicationFormTemplate.name" />
@@ -37,7 +38,12 @@
</template>
<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 type { FormElementId } from '~~/types/formElement'
import { useUserStore } from '~~/stores/useUserStore'
@@ -71,12 +77,16 @@ const validationMap = ref<Map<FormElementId, ComplianceStatus> | undefined>()
const validationStatus = ref<ComplianceStatus>(ComplianceStatus.NonCritical)
const allFormElements = computed(() => {
return applicationFormTemplate.value?.formElementSections?.flatMap((section) => section.formElements) ?? []
return (
applicationFormTemplate.value?.formElementSections?.flatMap(
(section: FormElementSectionDto) => section.formElements
) ?? []
)
})
watch(
() => allFormElements.value,
(updatedFormElements) => {
(updatedFormElements: FormElementDto[]) => {
validationMap.value = validateFormElements(updatedFormElements)
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() {
if (!applicationFormTemplate.value) {
console.error('Application form data is undefined')