Skip to content

Commit

Permalink
Add support for formdata change in modal form.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Dec 20, 2024
1 parent ee5a224 commit 2f55d58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/volto/src/components/manage/Form/ModalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,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,
},
});
}
}

/**
Expand Down
11 changes: 10 additions & 1 deletion packages/volto/src/components/manage/Widgets/SchemaWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ map(['Email', 'label_email'], (factory) => {
method: (intl) => ({
type: 'string',
widget: 'email',
id: 'email',
factory,
}),
});
Expand Down Expand Up @@ -1000,7 +1001,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,
Expand Down Expand Up @@ -1611,6 +1612,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 (
<div>
<Segment.Group
Expand Down Expand Up @@ -1757,6 +1765,7 @@ class SchemaWidget extends Component {
formData={{
factory:
find(choices, { value: 'label_text_field' }) || undefined,
id,
}}
schema={schemaField(
this.state.addField,
Expand Down

0 comments on commit 2f55d58

Please sign in to comment.