fix(universal-form-modal): 수정 모드에서 옵셔널 필드 그룹 자동 활성화
- 기존 데이터의 triggerField 값이 triggerValueOnAdd와 일치하면 그룹 자동 활성화 - 활성화된 그룹의 필드값도 기존 데이터로 초기화 - 신규 등록 모드에서는 기존대로 비활성화 상태 유지
This commit is contained in:
parent
0810debd2b
commit
132cf4cd7d
|
|
@ -355,6 +355,7 @@ export function UniversalFormModalComponent({
|
|||
const newFormData: FormDataState = {};
|
||||
const newRepeatSections: { [sectionId: string]: RepeatSectionItem[] } = {};
|
||||
const newCollapsed = new Set<string>();
|
||||
const newActivatedGroups = new Set<string>();
|
||||
|
||||
// 섹션별 초기화
|
||||
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 || {});
|
||||
|
||||
// 채번규칙 자동 생성
|
||||
|
|
|
|||
Loading…
Reference in New Issue