2
0

🐛 (js) Enable prefill for date input

This commit is contained in:
Baptiste Arnaud
2023-03-13 10:17:16 +01:00
parent f9aef907e3
commit a66a1e8226
4 changed files with 16 additions and 3 deletions

View File

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

View File

@ -152,6 +152,7 @@ const Input = (props: {
<Match when={props.block.type === InputBlockType.DATE}>
<DateForm
options={props.block.options as DateInputOptions}
defaultValue={getPrefilledValue()}
onSubmit={onSubmit}
/>
</Match>

View File

@ -7,10 +7,14 @@ import { parseReadableDate } from '../utils/parseReadableDate'
type Props = {
onSubmit: (inputValue: InputSubmitContent) => void
options?: DateInputOptions
defaultValue?: string
}
export const DateForm = (props: Props) => {
const [inputValues, setInputValues] = createSignal({ from: '', to: '' })
const [inputValues, setInputValues] = createSignal(
parseDefaultValue(props.defaultValue ?? '')
)
return (
<div class="flex flex-col">
<div class="flex items-center">
@ -50,6 +54,7 @@ export const DateForm = (props: Props) => {
'min-width': '100px',
'font-size': '16px',
}}
value={inputValues().from}
type={props.options?.hasTime ? 'datetime-local' : 'date'}
onChange={(e) =>
setInputValues({
@ -74,6 +79,7 @@ export const DateForm = (props: Props) => {
'min-width': '100px',
'font-size': '16px',
}}
value={inputValues().to}
type={props.options.hasTime ? 'datetime-local' : 'date'}
onChange={(e) =>
setInputValues({
@ -98,3 +104,9 @@ export const DateForm = (props: Props) => {
</div>
)
}
const parseDefaultValue = (defaultValue: string) => {
if (!defaultValue.includes('to')) return { from: defaultValue, to: '' }
const [from, to] = defaultValue.split(' to ')
return { from, to }
}

View File

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