Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset global Form state onSubmit and onCancel in Add and Edit forms - Backport #5827 #5828

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 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 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 @@ -154,6 +159,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 @@ -207,6 +213,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 @@ -470,7 +477,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 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 @@ -182,6 +183,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 @@ -257,6 +259,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 @@ -524,6 +527,7 @@ export default compose(
getSchema,
lockContent,
unlockContent,
setFormData,
},
),
preloadLazyLibs('cms'),
Expand Down
Loading