2
0

🐛 (numberInput) Fix input clearing out on dot or comma press

This commit is contained in:
Baptiste Arnaud
2023-10-25 17:37:45 +02:00
parent c2a08c482e
commit 4b248d554f
8 changed files with 69 additions and 15 deletions

View File

@@ -0,0 +1 @@
export const parseNumber = (value: string) => Number(value).toString()

View File

@@ -1 +1,10 @@
export const validateNumber = (inputValue: string) => !isNaN(Number(inputValue))
import { isNotDefined } from '@typebot.io/lib'
import { NumberInputBlock } from '@typebot.io/schemas'
export const validateNumber = (
inputValue: string,
options: NumberInputBlock['options']
) =>
inputValue !== '' &&
(isNotDefined(options?.min) || Number(inputValue) >= Number(options.min)) &&
(isNotDefined(options?.max) || Number(inputValue) <= Number(options.max))

View File

@@ -30,6 +30,7 @@ import { parseVariables } from './variables/parseVariables'
import { updateVariablesInSession } from './variables/updateVariablesInSession'
import { startBotFlow } from './startBotFlow'
import { TRPCError } from '@trpc/server'
import { parseNumber } from './blocks/inputs/number/parseNumber'
type Params = {
version: 1 | 2
@@ -344,9 +345,9 @@ const parseReply =
}
case InputBlockType.NUMBER: {
if (!inputValue) return { status: 'fail' }
const isValid = validateNumber(inputValue)
const isValid = validateNumber(inputValue, block.options)
if (!isValid) return { status: 'fail' }
return { status: 'success', reply: inputValue }
return { status: 'success', reply: parseNumber(inputValue) }
}
case InputBlockType.DATE: {
if (!inputValue) return { status: 'fail' }