From 988b47e7615385e7b48b6c2148bfe5e75f73cb1e Mon Sep 17 00:00:00 2001 From: Rob Gietema Date: Thu, 19 Dec 2024 16:19:14 -0700 Subject: [PATCH] Add support for formdata change in modal form. --- .../volto/src/components/manage/Form/ModalForm.jsx | 14 ++++++++++++++ .../src/components/manage/Widgets/SchemaWidget.jsx | 11 ++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/volto/src/components/manage/Form/ModalForm.jsx b/packages/volto/src/components/manage/Form/ModalForm.jsx index e52a8ef77a..354d0cb32b 100644 --- a/packages/volto/src/components/manage/Form/ModalForm.jsx +++ b/packages/volto/src/components/manage/Form/ModalForm.jsx @@ -219,6 +219,20 @@ class ModalForm extends Component { this.props.onChangeFormData(this.state.formData); } } + if (!isEqual(prevProps.formData, this.props.formData)) { + let newFormData = {}; + map(keys(this.props.formData), (field) => { + if (!isEqual(prevProps.formData[field], this.props.formData[field])) { + newFormData[field] = this.props.formData[field]; + } + }); + this.setState({ + formData: { + ...this.state.formData, + ...newFormData, + }, + }); + } } /** diff --git a/packages/volto/src/components/manage/Widgets/SchemaWidget.jsx b/packages/volto/src/components/manage/Widgets/SchemaWidget.jsx index 70ba12cbae..5dca6c540b 100644 --- a/packages/volto/src/components/manage/Widgets/SchemaWidget.jsx +++ b/packages/volto/src/components/manage/Widgets/SchemaWidget.jsx @@ -455,6 +455,7 @@ map(['Email', 'label_email'], (factory) => { method: (intl) => ({ type: 'string', widget: 'email', + id: 'email', factory, }), }); @@ -1002,7 +1003,7 @@ class SchemaWidget extends Component { values.factory === 'label_multi_choice_field'; const initialData = utility.method - ? utility.method(this.props.intl) + ? omit(utility.method(this.props.intl), ['id']) : { type: 'string', factory: values.factory, @@ -1613,6 +1614,13 @@ class SchemaWidget extends Component { 'generated', ); + const utility = config.getUtility({ + name: this.state.addField, + type: 'fieldFactoryInitialData', + }); + + const id = utility?.method ? utility.method(this.props.intl).id : undefined; + return (