2
0

🐛 Fix autocomplete submit

Closes #1402
This commit is contained in:
Baptiste Arnaud
2024-04-03 10:18:55 +02:00
parent 68ad0f2d4c
commit b5dd12c6fe
9 changed files with 24 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.2.61",
"version": "0.2.62",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",

View File

@ -23,7 +23,8 @@ export const EmailInput = (props: Props) => {
inputRef?.value !== '' && inputRef?.reportValidity()
const submit = () => {
if (checkIfInputIsValid()) props.onSubmit({ value: inputValue() })
if (checkIfInputIsValid())
props.onSubmit({ value: inputRef?.value ?? inputValue() })
else inputRef?.focus()
}

View File

@ -27,7 +27,7 @@ export const NumberInput = (props: NumberInputProps) => {
const submit = () => {
if (checkIfInputIsValid())
props.onSubmit({ value: inputValue().toString() })
props.onSubmit({ value: inputRef?.value ?? inputValue().toString() })
else inputRef?.focus()
}

View File

@ -63,13 +63,14 @@ export const PhoneInput = (props: PhoneInputProps) => {
const selectedCountryDialCode = phoneCountries.find(
(country) => country.code === selectedCountryCode()
)?.dial_code
if (checkIfInputIsValid())
if (checkIfInputIsValid()) {
const val = inputRef?.value ?? inputValue()
props.onSubmit({
value: inputValue().startsWith('+')
? inputValue()
: `${selectedCountryDialCode ?? ''}${inputValue()}`,
value: val.startsWith('+')
? val
: `${selectedCountryDialCode ?? ''}${val}`,
})
else inputRef?.focus()
} else inputRef?.focus()
}
const submitWhenEnter = (e: KeyboardEvent) => {

View File

@ -23,7 +23,8 @@ export const TextInput = (props: Props) => {
inputRef?.value !== '' && inputRef?.reportValidity()
const submit = () => {
if (checkIfInputIsValid()) props.onSubmit({ value: inputValue() })
if (checkIfInputIsValid())
props.onSubmit({ value: inputRef?.value ?? inputValue() })
else inputRef?.focus()
}

View File

@ -29,7 +29,8 @@ export const UrlInput = (props: Props) => {
inputRef?.value !== '' && inputRef?.reportValidity()
const submit = () => {
if (checkIfInputIsValid()) props.onSubmit({ value: inputValue() })
if (checkIfInputIsValid())
props.onSubmit({ value: inputRef?.value ?? inputValue() })
else inputRef?.focus()
}

View File

@ -25,8 +25,13 @@ export const guessApiHost = (
return chatApiUrl
}
return (
getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(',')[0] ??
chatApiCloudFallbackHost
const viewerUrls = getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(
','
) as string[] | undefined
const matchedUrl = viewerUrls?.find((url) =>
window.location.href.startsWith(url)
)
return matchedUrl ?? chatApiCloudFallbackHost
}

View File

@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.2.61",
"version": "0.2.62",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.2.61",
"version": "0.2.62",
"description": "Convenient library to display typebots on your React app",
"main": "dist/index.js",
"types": "dist/index.d.ts",