Skip to content

Commit

Permalink
Reset global Form state onSubmit and onCancel in Add and Edit forms. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh authored Mar 4, 2024
1 parent 511550f commit 64e7cf2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/5827.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reset global Form state onSubmit and onCancel in Add and Edit forms @sneridagh
11 changes: 9 additions & 2 deletions packages/volto/src/components/manage/Add/Add.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import { v4 as uuid } from 'uuid';
import qs from 'query-string';
import { toast } from 'react-toastify';

import { createContent, getSchema, changeLanguage } from '@plone/volto/actions';
import {
createContent,
getSchema,
changeLanguage,
setFormData,
} from '@plone/volto/actions';
import {
Form,
Icon,
Expand Down Expand Up @@ -159,6 +164,7 @@ class Add extends Component {
nextProps.createRequest.loaded &&
nextProps.content['@type'] === this.props.type
) {
this.props.setFormData({});
this.props.history.push(
this.props.returnUrl || flattenToAppURL(nextProps.content['@id']),
);
Expand Down Expand Up @@ -229,6 +235,7 @@ class Add extends Component {
* @returns {undefined}
*/
onCancel() {
this.props.setFormData({});
if (this.props.location?.state?.translationOf) {
const language = this.props.location.state.languageFrom;
const langFileName = toGettextLang(language);
Expand Down Expand Up @@ -490,7 +497,7 @@ export default compose(
returnUrl: qs.parse(props.location.search).return_url,
type: qs.parse(props.location.search).type,
}),
{ createContent, getSchema, changeLanguage },
{ createContent, getSchema, changeLanguage, setFormData },
),
preloadLazyLibs('cms'),
)(Add);
4 changes: 4 additions & 0 deletions packages/volto/src/components/manage/Edit/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
unlockContent,
getSchema,
listActions,
setFormData,
} from '@plone/volto/actions';
import {
flattenToAppURL,
Expand Down Expand Up @@ -187,6 +188,7 @@ class Edit extends Component {
});
}
if (this.props.updateRequest.loading && nextProps.updateRequest.loaded) {
this.props.setFormData({});
this.props.history.push(
this.props.returnUrl || getBaseUrl(this.props.pathname),
);
Expand Down Expand Up @@ -279,6 +281,7 @@ class Edit extends Component {
* @returns {undefined}
*/
onCancel() {
this.props.setFormData({});
this.props.history.push(
this.props.returnUrl || getBaseUrl(this.props.pathname),
);
Expand Down Expand Up @@ -545,6 +548,7 @@ export default compose(
getSchema,
lockContent,
unlockContent,
setFormData,
},
),
preloadLazyLibs('cms'),
Expand Down

0 comments on commit 64e7cf2

Please sign in to comment.