Skip to content

Commit

Permalink
bubble modified changes to the parents of nested forms
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Jun 18, 2024
1 parent 4961649 commit 3e0bc19
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/Webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,14 @@ export default class Webform extends NestedDataComponent {
onChange(flags, changed, modified, changes) {
flags = flags || {};
let isChangeEventEmitted = false;
super.onChange(flags, true);
// If this Webform is a nested form, continue to bubble change
// to the root
if (this.parent?.subForm === this) {
super.onChange({...flags, modified}, false);

Check failure on line 1403 in src/Webform.js

View workflow job for this annotation

GitHub Actions / setup

A space is required after '{'

Check failure on line 1403 in src/Webform.js

View workflow job for this annotation

GitHub Actions / setup

A space is required before '}'
}
else {
super.onChange(flags, true);
}
const value = _.clone(this.submission);
flags.changed = value.changed = changed;
flags.changes = changes;
Expand Down
4 changes: 2 additions & 2 deletions src/components/form/Form.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ describe('SaveDraft functionality for Nested Form', () => {
done();
});

it('Should save draft for Nested Form', function(done) {
it('Should save draft for Nested Form and for the Parent Form', function(done) {
const formElement = document.createElement('div');
Formio.createForm(
formElement,
Expand All @@ -386,7 +386,7 @@ describe('SaveDraft functionality for Nested Form', () => {
const inputEvent = new Event('input');
tfNestedInput.dispatchEvent(inputEvent);
setTimeout(() => {
assert.equal(saveDraftCalls, 1);
assert.equal(saveDraftCalls, 2);
assert.equal(state, 'draft');
done();
}, 1000);
Expand Down
4 changes: 2 additions & 2 deletions test/forms/helpers/testBasicComponentSettings/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ export default {
assert.deepEqual(basis, basisComponentNewValue, 'Should set basis component value');
checkCalculatedValue();
done();
}, 250);
}, 250);
}, 300);
}, 300);
},
'Should not allow overriding component colculated value'(form, done) {
const basisComponent = form.getComponent('basis');
Expand Down

0 comments on commit 3e0bc19

Please sign in to comment.