From 132cf4cd7d1ffa7d01bc702b6f1117cc518bf740 Mon Sep 17 00:00:00 2001 From: SeongHyun Kim Date: Wed, 17 Dec 2025 15:27:28 +0900 Subject: [PATCH] =?UTF-8?q?fix(universal-form-modal):=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20=EB=AA=A8=EB=93=9C=EC=97=90=EC=84=9C=20=EC=98=B5=EC=85=94?= =?UTF-8?q?=EB=84=90=20=ED=95=84=EB=93=9C=20=EA=B7=B8=EB=A3=B9=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=20=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 데이터의 triggerField 값이 triggerValueOnAdd와 일치하면 그룹 자동 활성화 - 활성화된 그룹의 필드값도 기존 데이터로 초기화 - 신규 등록 모드에서는 기존대로 비활성화 상태 유지 --- .../UniversalFormModalComponent.tsx | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx b/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx index 3c47a1ba..68a1553c 100644 --- a/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx +++ b/frontend/lib/registry/components/universal-form-modal/UniversalFormModalComponent.tsx @@ -355,6 +355,7 @@ export function UniversalFormModalComponent({ const newFormData: FormDataState = {}; const newRepeatSections: { [sectionId: string]: RepeatSectionItem[] } = {}; const newCollapsed = new Set(); + const newActivatedGroups = new Set(); // 섹션별 초기화 for (const section of config.sections) { @@ -391,10 +392,31 @@ export function UniversalFormModalComponent({ newFormData[field.columnName] = value; } - // 옵셔널 필드 그룹의 연동 필드 기본값 설정 - // triggerValueOnRemove 값을 기본값으로 사용 (옵셔널 그룹이 비활성화 상태일 때의 기본값) + // 옵셔널 필드 그룹 처리 if (section.optionalFieldGroups) { for (const group of section.optionalFieldGroups) { + const key = `${section.id}-${group.id}`; + + // 수정 모드: triggerField 값이 triggerValueOnAdd와 일치하면 그룹 자동 활성화 + if (effectiveInitialData && group.triggerField && group.triggerValueOnAdd !== undefined) { + const triggerValue = effectiveInitialData[group.triggerField]; + if (triggerValue === group.triggerValueOnAdd) { + newActivatedGroups.add(key); + console.log(`[initializeForm] 옵셔널 그룹 자동 활성화: ${key}, triggerField=${group.triggerField}, value=${triggerValue}`); + + // 활성화된 그룹의 필드값도 초기화 + for (const field of group.fields) { + let value = field.defaultValue ?? ""; + const parentField = field.parentFieldName || field.columnName; + if (effectiveInitialData[parentField] !== undefined) { + value = effectiveInitialData[parentField]; + } + newFormData[field.columnName] = value; + } + } + } + + // 신규 등록 모드: triggerValueOnRemove를 기본값으로 설정 if (group.triggerField && group.triggerValueOnRemove !== undefined) { // effectiveInitialData에 해당 값이 없는 경우에만 기본값 설정 if (!effectiveInitialData || effectiveInitialData[group.triggerField] === undefined) { @@ -409,6 +431,7 @@ export function UniversalFormModalComponent({ setFormData(newFormData); setRepeatSections(newRepeatSections); setCollapsedSections(newCollapsed); + setActivatedOptionalFieldGroups(newActivatedGroups); setOriginalData(effectiveInitialData || {}); // 채번규칙 자동 생성