-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 (numberInput) Fix input clearing out on dot or comma press
- Loading branch information
1 parent
c2a08c4
commit 4b248d5
Showing
8 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const parseNumber = (value: string) => Number(value).toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/embeds/js/src/features/blocks/inputs/number/numberInputHelper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createEffect, untrack } from 'solid-js' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const numberInputHelper = function (value: () => any) { | ||
const bindDirective = function (el: HTMLInputElement) { | ||
createEffect(function () { | ||
const v = value() | ||
if (v == null) { | ||
el.value = v | ||
return | ||
} | ||
|
||
const nodeV = el.value | ||
if ((v === 0 && nodeV === '') || v != nodeV) { | ||
el.value = v + '' | ||
} | ||
}) | ||
} | ||
const targetValue = function (el: HTMLInputElement) { | ||
if (el.validity.badInput) { | ||
return value() | ||
} | ||
|
||
if (el.value == '') { | ||
return undefined | ||
} | ||
|
||
return el.valueAsNumber | ||
} | ||
|
||
return [untrack(value), bindDirective, targetValue] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4b248d5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
builder-v2 – ./apps/builder
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io