Skip to content

Commit

Permalink
Set default values based on querystring.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Sep 11, 2024
1 parent 8f72b7e commit de1b655
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 = () => {};

Expand Down Expand Up @@ -67,7 +76,7 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => {
return (
<Form
schema={data.schema}
formData={{}}
formData={initialData}
onSubmit={onSubmit}
resetOnCancel={true}
onCancel={data.show_cancel ? onCancel : null}
Expand Down

0 comments on commit de1b655

Please sign in to comment.