From 2410ebb7dcf6b74193767fa1aae1d3c7513a5336 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 24 Mar 2026 09:10:26 +0100 Subject: [PATCH] fix(custom-fields) : preserve defaultValue and IDs in piece structure editor Co-Authored-By: Claude Opus 4.6 (1M context) --- app/composables/usePieceStructureEditorLogic.ts | 9 +++++++++ app/shared/model/pieceProductStructure.ts | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/composables/usePieceStructureEditorLogic.ts b/app/composables/usePieceStructureEditorLogic.ts index 4d610fe..0734bc9 100644 --- a/app/composables/usePieceStructureEditorLogic.ts +++ b/app/composables/usePieceStructureEditorLogic.ts @@ -81,6 +81,12 @@ const toEditorField = ( type: baseType as PieceModelCustomFieldType, required: Boolean(input?.required), optionsText, + defaultValue: + input?.defaultValue !== undefined && input.defaultValue !== null && input.defaultValue !== '' + ? String(input.defaultValue) + : null, + ...(typeof input?.id === 'string' && input.id ? { id: input.id } : {}), + ...(typeof input?.customFieldId === 'string' && input.customFieldId ? { customFieldId: input.customFieldId } : {}), orderIndex: typeof input?.orderIndex === 'number' ? input.orderIndex : index, } } @@ -164,6 +170,9 @@ const buildPayload = ( if (field.customFieldId) { payload.customFieldId = field.customFieldId } + if (field.defaultValue !== undefined && field.defaultValue !== null && field.defaultValue !== '') { + payload.defaultValue = String(field.defaultValue) + } if (type === 'select') { const options = normalizeLineEndings(field.optionsText) diff --git a/app/shared/model/pieceProductStructure.ts b/app/shared/model/pieceProductStructure.ts index 8e2368e..24a1c7c 100644 --- a/app/shared/model/pieceProductStructure.ts +++ b/app/shared/model/pieceProductStructure.ts @@ -86,6 +86,19 @@ const sanitizePieceCustomFields = (fields: any[]): PieceModelCustomField[] => { if (options) { result.options = options } + const defaultValue = + field?.defaultValue !== undefined && field?.defaultValue !== null && field?.defaultValue !== '' + ? String(field.defaultValue) + : null + if (defaultValue !== null) { + result.defaultValue = defaultValue + } + if (typeof field?.id === 'string' && field.id) { + result.id = field.id + } + if (typeof field?.customFieldId === 'string' && field.customFieldId) { + result.customFieldId = field.customFieldId + } const orderIndex = typeof field?.orderIndex === 'number' ? field.orderIndex : index result.orderIndex = orderIndex return result