From 559c6ae3342334ecce57084079fbf4b947ec6c69 Mon Sep 17 00:00:00 2001 From: Rob Gietema Date: Sat, 5 Oct 2024 14:30:58 +0200 Subject: [PATCH] Filter data to be send. --- .../packages/volto-form-block/src/index.js | 1 + .../src/schemaFormBlock/ViewSchemaForm.jsx | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/packages/volto-form-block/src/index.js b/frontend/packages/volto-form-block/src/index.js index b611844..c415b68 100644 --- a/frontend/packages/volto-form-block/src/index.js +++ b/frontend/packages/volto-form-block/src/index.js @@ -85,6 +85,7 @@ const applyConfig = (config) => { { value: 'number', label: 'Number' }, { value: 'time', label: 'Time' }, ], + filterFactorySend: ['static_text'], defaultSender: 'noreply@plone.org', defaultSenderName: 'Plone', additionalFields: [], diff --git a/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx b/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx index 13548e4..2fe3c8a 100644 --- a/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx +++ b/frontend/packages/volto-form-block/src/schemaFormBlock/ViewSchemaForm.jsx @@ -8,7 +8,8 @@ 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'; +import { includes, keys, pickBy } from 'lodash'; +import config from '@plone/volto/registry'; const messages = defineMessages({ error: { @@ -38,16 +39,26 @@ const FormBlockView = ({ data, id, properties, metadata, path }) => { const onCancel = () => {}; const onSubmit = (formData) => { + let submitData = { ...formData }; let captcha = { provider: data.captcha, - token: formData.captchaToken, + token: submitData.captchaToken, }; if (data.captcha === 'honeypot') { - captcha.value = formData['captchaWidget']?.value ?? ''; - delete formData.captchaToken; + captcha.value = submitData['captchaWidget']?.value ?? ''; + delete submitData.captchaToken; } - dispatch(submitForm(path, id, formData, captcha)).catch((err) => { + submitData = pickBy( + submitData, + (value, field) => + !includes( + config.blocks.blocksConfig.schemaForm.filterFactorySend, + data.schema.properties[field].factory, + ), + ); + + dispatch(submitForm(path, id, submitData, captcha)).catch((err) => { let message = err?.response?.body?.error?.message || err?.response?.body?.message ||