Skip to content

Commit

Permalink
Merge pull request #5604 from formio/FIO-8360-On-submit,-nested-form-…
Browse files Browse the repository at this point in the history
…submission-state-doesnot-change-to-submitted
  • Loading branch information
brendanbond authored May 17, 2024
2 parents a442792 + 02ffada commit 778e9c0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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));
});
});

0 comments on commit 778e9c0

Please sign in to comment.