From 5b0062003f36deb181553e751bdf4fd8790fb5c5 Mon Sep 17 00:00:00 2001 From: Valentin Serra Date: Tue, 23 Apr 2024 08:43:48 +0200 Subject: [PATCH] fix: ensure output data is in sync with instance registration --- .../form-js-playground/src/components/PlaygroundRoot.js | 9 ++++++--- .../form-js-viewer/src/core/FormFieldInstanceRegistry.js | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/form-js-playground/src/components/PlaygroundRoot.js b/packages/form-js-playground/src/components/PlaygroundRoot.js index 967f179eb..b89a3040c 100644 --- a/packages/form-js-playground/src/components/PlaygroundRoot.js +++ b/packages/form-js-playground/src/components/PlaygroundRoot.js @@ -133,11 +133,14 @@ export function PlaygroundRoot(config) { emit('formPlayground.rendered'); }); - // pipe viewer changes to output data editor - formViewer.on('changed', () => { + const updateOutputData = () => { const submitData = formViewer._getSubmitData(); outputDataEditor.setValue(toString(submitData)); - }); + }; + + // pipe viewer changes to output data editor + formViewer.on('changed', updateOutputData); + formViewer.on('formFieldInstanceRegistry.changed', updateOutputData); inputDataEditor.on('changed', (event) => { try { diff --git a/packages/form-js-viewer/src/core/FormFieldInstanceRegistry.js b/packages/form-js-viewer/src/core/FormFieldInstanceRegistry.js index 8281a9d73..57e4e083f 100644 --- a/packages/form-js-viewer/src/core/FormFieldInstanceRegistry.js +++ b/packages/form-js-viewer/src/core/FormFieldInstanceRegistry.js @@ -26,6 +26,8 @@ export class FormFieldInstanceRegistry { indexes, }; + this._eventBus.fire('formFieldInstanceRegistry.changed', { instanceId, action: 'added' }); + return instanceId; } @@ -35,6 +37,8 @@ export class FormFieldInstanceRegistry { } delete this._formFieldInstances[instanceId]; + + this._eventBus.fire('formFieldInstanceRegistry.changed', { instanceId, action: 'removed' }); } getAll() {