feat: Add Eingabeseite 10 (Schlussteil), fix section spawning with multiple conditions
This commit is contained in:
@@ -18,7 +18,7 @@ export function useSectionSpawning() {
|
||||
|
||||
// Process each trigger independently
|
||||
for (const trigger of triggers) {
|
||||
resultSections = processSingleTrigger(resultSections, formElement, trigger, triggerValue)
|
||||
resultSections = processSingleTrigger(resultSections, formElement, trigger, triggerValue, triggers)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ export function useSectionSpawning() {
|
||||
sections: FormElementSectionDto[],
|
||||
formElement: FormElementDto,
|
||||
trigger: SectionSpawnTriggerDto,
|
||||
triggerValue: string
|
||||
triggerValue: string,
|
||||
allTriggersForElement: SectionSpawnTriggerDto[]
|
||||
): FormElementSectionDto[] {
|
||||
let resultSections = sections
|
||||
const shouldSpawn = shouldSpawnSection(trigger, triggerValue)
|
||||
@@ -45,9 +46,19 @@ export function useSectionSpawning() {
|
||||
if (shouldSpawn && !existingSpawnedSection) {
|
||||
resultSections = spawnNewSection(resultSections, formElement, trigger, triggerValue)
|
||||
}
|
||||
// 2. Condition no longer met but section exists → remove spawned section
|
||||
// 2. Condition no longer met but section exists → remove spawned section only if no other
|
||||
// trigger for the same template reference still satisfies the spawn condition (OR logic)
|
||||
else if (!shouldSpawn && existingSpawnedSection) {
|
||||
resultSections = removeSpawnedSectionForTrigger(resultSections, formElement.reference!, trigger.templateReference)
|
||||
const otherTriggerAlsoSpawns = allTriggersForElement.some(
|
||||
(t) => t !== trigger && t.templateReference === trigger.templateReference && shouldSpawnSection(t, triggerValue)
|
||||
)
|
||||
if (!otherTriggerAlsoSpawns) {
|
||||
resultSections = removeSpawnedSectionForTrigger(
|
||||
resultSections,
|
||||
formElement.reference!,
|
||||
trigger.templateReference
|
||||
)
|
||||
}
|
||||
}
|
||||
// 3. Condition still met and section exists → update section titles if value changed
|
||||
else if (shouldSpawn && existingSpawnedSection && triggerValue) {
|
||||
|
||||
Reference in New Issue
Block a user