From 3e0bc199195b8b55e1622b23f2a85b211b5e6b19 Mon Sep 17 00:00:00 2001 From: brendanjbond Date: Tue, 18 Jun 2024 00:48:28 -0600 Subject: [PATCH] bubble modified changes to the parents of nested forms --- src/Webform.js | 9 ++++++++- src/components/form/Form.unit.js | 4 ++-- test/forms/helpers/testBasicComponentSettings/tests.js | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Webform.js b/src/Webform.js index fe809b6a6d..ddfeb4bb99 100644 --- a/src/Webform.js +++ b/src/Webform.js @@ -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); + } + else { + super.onChange(flags, true); + } const value = _.clone(this.submission); flags.changed = value.changed = changed; flags.changes = changes; diff --git a/src/components/form/Form.unit.js b/src/components/form/Form.unit.js index 8a0b8bd686..f0feedfa1a 100644 --- a/src/components/form/Form.unit.js +++ b/src/components/form/Form.unit.js @@ -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, @@ -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); diff --git a/test/forms/helpers/testBasicComponentSettings/tests.js b/test/forms/helpers/testBasicComponentSettings/tests.js index abc7874bb5..8a864a70a6 100644 --- a/test/forms/helpers/testBasicComponentSettings/tests.js +++ b/test/forms/helpers/testBasicComponentSettings/tests.js @@ -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');