🐛 (numberInput) Fix input clearing out on dot or comma press
This commit is contained in:
1
packages/bot-engine/blocks/inputs/number/parseNumber.ts
Normal file
1
packages/bot-engine/blocks/inputs/number/parseNumber.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const parseNumber = (value: string) => Number(value).toString()
|
||||
@@ -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))
|
||||
|
||||
@@ -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' }
|
||||
|
||||
Reference in New Issue
Block a user