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", "name": "@typebot.io/js",
"version": "0.2.61", "version": "0.2.62",
"description": "Javascript library to display typebots on your website", "description": "Javascript library to display typebots on your website",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -25,8 +25,13 @@ export const guessApiHost = (
return chatApiUrl return chatApiUrl
} }
return ( const viewerUrls = getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(
getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(',')[0] ?? ','
chatApiCloudFallbackHost ) 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", "name": "@typebot.io/nextjs",
"version": "0.2.61", "version": "0.2.62",
"description": "Convenient library to display typebots on your Next.js website", "description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

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