From 954cc10c60a9162365a1455d10d0b64952de07cc Mon Sep 17 00:00:00 2001 From: mortezaei Date: Sat, 22 Aug 2026 16:15:45 +0330 Subject: [PATCH] fix(question-storage): only use option_id for choice questions so scalar number questions preserve numeric values --- .../Componentes/question-answer-storage.tsx | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/components/Componentes/question-answer-storage.tsx b/src/components/Componentes/question-answer-storage.tsx index b8be8f9..eba104c 100644 --- a/src/components/Componentes/question-answer-storage.tsx +++ b/src/components/Componentes/question-answer-storage.tsx @@ -261,7 +261,18 @@ function createPayload( function fieldsToAnswers(fields: MarriageField[]) { return fields.reduce((nextAnswers, field) => { - if (field.option_id !== undefined && field.option_id !== null) { + const isChoice = + field.type === "dropdown" || + field.type === "radio" || + field.type === "checkbox" || + field.type === "scale"; + + if ( + isChoice && + field.option_id !== undefined && + field.option_id !== null && + (!Array.isArray(field.option_id) || field.option_id.length > 0 || field.type === "checkbox") + ) { nextAnswers[field.key] = { ...field, value: field.option_id, @@ -640,11 +651,27 @@ export function QuestionAnswersProvider({ if (question) { // Only update if there are no newer local dirty edits for this key if (!dirtyKeysRef.current.has(key)) { + const isChoice = + question.type === "dropdown" || + question.type === "radio" || + question.type === "checkbox" || + question.type === "scale"; + + const resolvedVal = + isChoice && + answer.option_id !== undefined && + answer.option_id !== null && + (!Array.isArray(answer.option_id) || + answer.option_id.length > 0 || + question.type === "checkbox") + ? answer.option_id + : answer.value; + nextAnswers[key] = { key, label: question.title, type: question.type, - value: answer.option_id ?? answer.value, + value: resolvedVal, option_id: answer.option_id, } as MarriageField; }