Skip to content

Commit

Permalink
Filter data to be send.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Oct 5, 2024
1 parent 52a42c0 commit 559c6ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions frontend/packages/volto-form-block/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 ||
Expand Down

0 comments on commit 559c6ae

Please sign in to comment.