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 19, 2024
1 parent 1df0a8e commit 988b47e
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 @@ -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,
},
});
}
}

/**
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 @@ -455,6 +455,7 @@ map(['Email', 'label_email'], (factory) => {
method: (intl) => ({
type: 'string',
widget: 'email',
id: 'email',
factory,
}),
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
<div>
<Segment.Group
Expand Down Expand Up @@ -1759,6 +1767,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 988b47e

Please sign in to comment.