🐛 (js) Enable prefill for date input
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/js",
|
"name": "@typebot.io/js",
|
||||||
"version": "0.0.25",
|
"version": "0.0.26",
|
||||||
"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",
|
||||||
|
@ -152,6 +152,7 @@ const Input = (props: {
|
|||||||
<Match when={props.block.type === InputBlockType.DATE}>
|
<Match when={props.block.type === InputBlockType.DATE}>
|
||||||
<DateForm
|
<DateForm
|
||||||
options={props.block.options as DateInputOptions}
|
options={props.block.options as DateInputOptions}
|
||||||
|
defaultValue={getPrefilledValue()}
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
|
@ -7,10 +7,14 @@ import { parseReadableDate } from '../utils/parseReadableDate'
|
|||||||
type Props = {
|
type Props = {
|
||||||
onSubmit: (inputValue: InputSubmitContent) => void
|
onSubmit: (inputValue: InputSubmitContent) => void
|
||||||
options?: DateInputOptions
|
options?: DateInputOptions
|
||||||
|
defaultValue?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DateForm = (props: Props) => {
|
export const DateForm = (props: Props) => {
|
||||||
const [inputValues, setInputValues] = createSignal({ from: '', to: '' })
|
const [inputValues, setInputValues] = createSignal(
|
||||||
|
parseDefaultValue(props.defaultValue ?? '')
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
@ -50,6 +54,7 @@ export const DateForm = (props: Props) => {
|
|||||||
'min-width': '100px',
|
'min-width': '100px',
|
||||||
'font-size': '16px',
|
'font-size': '16px',
|
||||||
}}
|
}}
|
||||||
|
value={inputValues().from}
|
||||||
type={props.options?.hasTime ? 'datetime-local' : 'date'}
|
type={props.options?.hasTime ? 'datetime-local' : 'date'}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setInputValues({
|
setInputValues({
|
||||||
@ -74,6 +79,7 @@ export const DateForm = (props: Props) => {
|
|||||||
'min-width': '100px',
|
'min-width': '100px',
|
||||||
'font-size': '16px',
|
'font-size': '16px',
|
||||||
}}
|
}}
|
||||||
|
value={inputValues().to}
|
||||||
type={props.options.hasTime ? 'datetime-local' : 'date'}
|
type={props.options.hasTime ? 'datetime-local' : 'date'}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setInputValues({
|
setInputValues({
|
||||||
@ -98,3 +104,9 @@ export const DateForm = (props: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parseDefaultValue = (defaultValue: string) => {
|
||||||
|
if (!defaultValue.includes('to')) return { from: defaultValue, to: '' }
|
||||||
|
const [from, to] = defaultValue.split(' to ')
|
||||||
|
return { from, to }
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/react",
|
"name": "@typebot.io/react",
|
||||||
"version": "0.0.25",
|
"version": "0.0.26",
|
||||||
"description": "React library to display typebots on your website",
|
"description": "React library to display typebots on your website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
Reference in New Issue
Block a user