Skip to content

Commit b5dd12c

Browse files
committed
🐛 Fix autocomplete submit
Closes baptisteArno#1402
1 parent 68ad0f2 commit b5dd12c

File tree

9 files changed

+24
-15
lines changed

9 files changed

+24
-15
lines changed

packages/embeds/js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typebot.io/js",
3-
"version": "0.2.61",
3+
"version": "0.2.62",
44
"description": "Javascript library to display typebots on your website",
55
"type": "module",
66
"main": "dist/index.js",

packages/embeds/js/src/features/blocks/inputs/email/components/EmailInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export const EmailInput = (props: Props) => {
2323
inputRef?.value !== '' && inputRef?.reportValidity()
2424

2525
const submit = () => {
26-
if (checkIfInputIsValid()) props.onSubmit({ value: inputValue() })
26+
if (checkIfInputIsValid())
27+
props.onSubmit({ value: inputRef?.value ?? inputValue() })
2728
else inputRef?.focus()
2829
}
2930

packages/embeds/js/src/features/blocks/inputs/number/components/NumberInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const NumberInput = (props: NumberInputProps) => {
2727

2828
const submit = () => {
2929
if (checkIfInputIsValid())
30-
props.onSubmit({ value: inputValue().toString() })
30+
props.onSubmit({ value: inputRef?.value ?? inputValue().toString() })
3131
else inputRef?.focus()
3232
}
3333

packages/embeds/js/src/features/blocks/inputs/phone/components/PhoneInput.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ export const PhoneInput = (props: PhoneInputProps) => {
6363
const selectedCountryDialCode = phoneCountries.find(
6464
(country) => country.code === selectedCountryCode()
6565
)?.dial_code
66-
if (checkIfInputIsValid())
66+
if (checkIfInputIsValid()) {
67+
const val = inputRef?.value ?? inputValue()
6768
props.onSubmit({
68-
value: inputValue().startsWith('+')
69-
? inputValue()
70-
: `${selectedCountryDialCode ?? ''}${inputValue()}`,
69+
value: val.startsWith('+')
70+
? val
71+
: `${selectedCountryDialCode ?? ''}${val}`,
7172
})
72-
else inputRef?.focus()
73+
} else inputRef?.focus()
7374
}
7475

7576
const submitWhenEnter = (e: KeyboardEvent) => {

packages/embeds/js/src/features/blocks/inputs/textInput/components/TextInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export const TextInput = (props: Props) => {
2323
inputRef?.value !== '' && inputRef?.reportValidity()
2424

2525
const submit = () => {
26-
if (checkIfInputIsValid()) props.onSubmit({ value: inputValue() })
26+
if (checkIfInputIsValid())
27+
props.onSubmit({ value: inputRef?.value ?? inputValue() })
2728
else inputRef?.focus()
2829
}
2930

packages/embeds/js/src/features/blocks/inputs/url/components/UrlInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export const UrlInput = (props: Props) => {
2929
inputRef?.value !== '' && inputRef?.reportValidity()
3030

3131
const submit = () => {
32-
if (checkIfInputIsValid()) props.onSubmit({ value: inputValue() })
32+
if (checkIfInputIsValid())
33+
props.onSubmit({ value: inputRef?.value ?? inputValue() })
3334
else inputRef?.focus()
3435
}
3536

packages/embeds/js/src/utils/guessApiHost.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ export const guessApiHost = (
2525
return chatApiUrl
2626
}
2727

28-
return (
29-
getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(',')[0] ??
30-
chatApiCloudFallbackHost
28+
const viewerUrls = getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(
29+
','
30+
) as string[] | undefined
31+
32+
const matchedUrl = viewerUrls?.find((url) =>
33+
window.___location.href.startsWith(url)
3134
)
35+
36+
return matchedUrl ?? chatApiCloudFallbackHost
3237
}

packages/embeds/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typebot.io/nextjs",
3-
"version": "0.2.61",
3+
"version": "0.2.62",
44
"description": "Convenient library to display typebots on your Next.js website",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/embeds/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typebot.io/react",
3-
"version": "0.2.61",
3+
"version": "0.2.62",
44
"description": "Convenient library to display typebots on your React app",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)