diff --git a/packages/bot-engine/src/contexts/TypebotContext.tsx b/packages/bot-engine/src/contexts/TypebotContext.tsx index af760c9b3..4928c34f1 100644 --- a/packages/bot-engine/src/contexts/TypebotContext.tsx +++ b/packages/bot-engine/src/contexts/TypebotContext.tsx @@ -67,9 +67,7 @@ export const TypebotContext = ({ }, [typebot.theme, typebot.settings]) const updateVariableValue = (variableId: string, value: string) => { - const formattedValue: string | number = isNaN(Number(value)) - ? value - : Number(value) + const formattedValue = formatIncomingVariableValue(value) setLocalTypebot((typebot) => ({ ...typebot, variables: typebot.variables.map((v) => @@ -136,4 +134,10 @@ export const TypebotContext = ({ ) } +const formatIncomingVariableValue = (value: string): string | number => { + // This first check avoid to parse 004 as the number 4. + if (value.startsWith('0') && value.length > 1) return value + return isNaN(Number(value)) ? value : Number(value) +} + export const useTypebot = () => useContext(typebotContext)