From de1b6551938fe04aba7119bcecce0c8bacb54e00 Mon Sep 17 00:00:00 2001 From: Rob Gietema Date: Wed, 11 Sep 2024 12:36:19 +0200 Subject: [PATCH] Set default values based on querystring. --- .../src/schemaFormBlock/ViewSchemaForm.jsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx b/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx index fbe41c9..b5cf18a 100644 --- a/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx +++ b/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx @@ -6,6 +6,9 @@ import { submitForm } from 'volto-form-block/actions'; import { tryParseJSON, extractInvariantErrors } from '@plone/volto/helpers'; import { toast } from 'react-toastify'; import { Toast } from '@plone/volto/components'; +import { useLocation } from 'react-router-dom'; +import qs from 'query-string'; +import { pickBy, keys } from 'lodash'; const messages = defineMessages({ error: { @@ -26,6 +29,12 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => { const dispatch = useDispatch(); const intl = useIntl(); let attachments = {}; + const location = useLocation(); + + const propertyNames = keys(data.schema.properties); + const initialData = pickBy(qs.parse(location.search), (value, key) => + propertyNames.includes(key), + ); const onCancel = () => {}; @@ -67,7 +76,7 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => { return (