feat(markdown-blocks/form): add support for hidden input fields in MarkdownForm component

pull/21922/head
mizoo-snow21 11 months ago
parent 37e19de7ab
commit c49dfcd298

@ -28,6 +28,7 @@ enum SUPPORTED_TYPES {
DATETIME = 'datetime', DATETIME = 'datetime',
CHECKBOX = 'checkbox', CHECKBOX = 'checkbox',
SELECT = 'select', SELECT = 'select',
HIDDEN = 'hidden',
} }
const MarkdownForm = ({ node }: any) => { const MarkdownForm = ({ node }: any) => {
const { onSend } = useChatContext() const { onSend } = useChatContext()
@ -37,8 +38,14 @@ const MarkdownForm = ({ node }: any) => {
useEffect(() => { useEffect(() => {
const initialValues: { [key: string]: any } = {} const initialValues: { [key: string]: any } = {}
node.children.forEach((child: any) => { node.children.forEach((child: any) => {
if ([SUPPORTED_TAGS.INPUT, SUPPORTED_TAGS.TEXTAREA].includes(child.tagName)) if ([SUPPORTED_TAGS.INPUT, SUPPORTED_TAGS.TEXTAREA].includes(child.tagName)) {
// Always set initial value for hidden inputs
if (child.tagName === SUPPORTED_TAGS.INPUT && child.properties.type === SUPPORTED_TYPES.HIDDEN) {
initialValues[child.properties.name] = child.properties.value || ''
} else {
initialValues[child.properties.name] = child.properties.value initialValues[child.properties.name] = child.properties.value
}
}
}) })
setFormValues(initialValues) setFormValues(initialValues)
}, [node.children]) }, [node.children])
@ -180,6 +187,19 @@ const MarkdownForm = ({ node }: any) => {
) )
} }
if (child.properties.type === SUPPORTED_TYPES.HIDDEN) {
// Hidden input is not displayed but maintains form value
return (
<input
key={index}
type="hidden"
name={child.properties.name}
value={formValues[child.properties.name] || child.properties.value || ''}
readOnly
/>
)
}
return ( return (
<Input <Input
key={index} key={index}

Loading…
Cancel
Save