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 || {}); // 채번규칙 자동 생성