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

FIO-8360 fixed submission state for nested form #5604

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
3 changes: 2 additions & 1 deletion src/components/form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,10 @@ export default class FormComponent extends Component {
}

const isAlreadySubmitted = submission && submission._id && submission.form;
const isDraftSubmission = this.options.saveDraft && submission.state === 'draft';

// This submission has already been submitted, so just return the reference data.
if (isAlreadySubmitted && !this.subForm?.wizard) {
if (isAlreadySubmitted && !this.subForm?.wizard && !isDraftSubmission) {
this.dataValue = submission;
return Promise.resolve(this.dataValue);
}
Expand Down
33 changes: 33 additions & 0 deletions src/components/form/Form.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ describe('SaveDraft functionality for Nested Form', () => {
let saveDraftCalls = 0;
let restoreDraftCalls = 0;
let state = null;
let subFormState = null;

const restoredDraftData = {
parent: 'test Parent',
Expand All @@ -299,6 +300,7 @@ describe('SaveDraft functionality for Nested Form', () => {
Formio.makeRequest = (formio, type, url, method, data) => {
if (type === 'submission' && ['put', 'post'].includes(method)) {
state = data.state;
subFormState = _.get(data, 'data.form.state', null);
if (state === 'draft') {
saveDraftCalls = ++saveDraftCalls;
}
Expand Down Expand Up @@ -345,6 +347,7 @@ describe('SaveDraft functionality for Nested Form', () => {
saveDraftCalls = 0;
restoreDraftCalls = 0;
state = null;
subFormState = null;
});

after((done) => {
Expand Down Expand Up @@ -394,4 +397,34 @@ describe('SaveDraft functionality for Nested Form', () => {
}, 200);
}).catch((err) => done(err));
});

it('Should change state of the nested sumbmission to submitted after submit parent form', function(done) {
const formElement = document.createElement('div');
Formio.createForm(
formElement,
'http://localhost:3000/idwqwhclwioyqbw/testdraftparent',
{
saveDraft: true
}
).then((form)=>{
setTimeout(()=>{
const tfNestedInput = form.getComponent('form.nested').refs.input[0];
tfNestedInput.value = 'testNested Update';
const inputEvent = new Event('input');
tfNestedInput.dispatchEvent(inputEvent);
setTimeout(()=>{
assert.equal(saveDraftCalls, 1);
const clickEvent = new Event('click');
const submitBtn = form.element.querySelector('[name="data[submit]"]');
submitBtn.dispatchEvent(clickEvent);
setTimeout(()=> {
assert.equal(saveDraftCalls, 1);
assert.equal(state, 'submitted');
assert.equal(subFormState, 'submitted');
done();
}, 500);
}, 300);
}, 200);
}).catch((err) => done(err));
});
});
Loading