diff --git a/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js b/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js index 3211ab0a3..06dba55a8 100644 --- a/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js +++ b/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js @@ -228,7 +228,7 @@ const RepetitionScaffold = (props) => { () => ({ data: parentExpressionContextInfo.data, this: itemValue, - parent: buildExpressionContext(parentExpressionContextInfo), + parent: buildExpressionContext({ ...parentExpressionContextInfo, data: parentExpressionContextInfo.this }), i: [...parentExpressionContextInfo.i, itemIndex + 1], }), [itemIndex, parentExpressionContextInfo, itemValue], diff --git a/packages/form-js-viewer/test/spec/Form.spec.js b/packages/form-js-viewer/test/spec/Form.spec.js index 5302847c1..c5a912e53 100644 --- a/packages/form-js-viewer/test/spec/Form.spec.js +++ b/packages/form-js-viewer/test/spec/Form.spec.js @@ -12,6 +12,7 @@ import conditionErrorsDynamicListSchema from './condition-errors-dynamic-list.js import dynamicListVariablesSchema from './dynamic-list-variables.json'; import dynamicListTableFilterInteractionSchema from './dynamic-list-table-filter-interaction.json'; import complexExpressionsSchema from './complex-expressions.json'; +import nestedComplexContextSchema from './nested-complex-context.json'; import cyclicalExpressionsSchema from './cyclical-expressions.json'; import chainExpressionsSchema from './chain-expressions.json'; import hiddenFieldsConditionalSchema from './hidden-fields-conditional.json'; @@ -1782,6 +1783,45 @@ describe('Form', function () { ]); }); }); + + describe('integration - context', function () { + it('should properly pass down context and parent accessors', async function () { + // given + const data = { + a: 'testA', + list: [ + { + b: 'testB', + }, + ], + }; + + // when + await bootstrapForm({ + container, + data, + schema: nestedComplexContextSchema, + }); + + // then + expect(form).to.exist; + + // Select all fjs-form-field-text elements + const textFields = container.querySelectorAll('.fjs-form-field-text'); + + // Check the contents of the first fjs-form-field-text element + expect(textFields[0]).to.exist; + expect(textFields[0].textContent).to.include('Flat: testA'); + expect(textFields[0].textContent).to.include('Parent: testA'); + + // Check the contents of the second fjs-form-field-text element + expect(textFields[1]).to.exist; + expect(textFields[1].textContent).to.include('ParentThis: testB'); + expect(textFields[1].textContent).to.include('Parent: testB'); + expect(textFields[1].textContent).to.include('GrandParent: testA'); + expect(textFields[1].textContent).to.include('GrandParentThis: testA'); + }); + }); }); // helpers ////////// diff --git a/packages/form-js-viewer/test/spec/nested-complex-context.json b/packages/form-js-viewer/test/spec/nested-complex-context.json new file mode 100644 index 000000000..32b682095 --- /dev/null +++ b/packages/form-js-viewer/test/spec/nested-complex-context.json @@ -0,0 +1,80 @@ +{ + "components": [ + { + "label": "Test", + "type": "textfield", + "layout": { + "row": "Row_06pau7i", + "columns": null + }, + "id": "Field_0naxgdd", + "key": "a" + }, + { + "components": [ + { + "text": "Flat: {{a}}\nParent: {{parent.a}}", + "label": "Text view", + "type": "text", + "layout": { + "row": "Row_0e00xn8", + "columns": null + }, + "id": "Field_03g3bvj" + }, + { + "label": "Test", + "type": "textfield", + "layout": { + "row": "Row_0nqe5bi", + "columns": null + }, + "id": "Field_0oofqh4", + "key": "b" + }, + { + "components": [ + { + "text": "ParentThis: {{parent.this.b}}\nParent: {{parent.b}}\nGrandParent: {{parent.parent.a}}\nGrandParentThis: {{parent.parent.this.a}}", + "label": "Text view", + "type": "text", + "layout": { + "row": "Row_17ftgn9", + "columns": null + }, + "id": "Field_1bjzda6" + } + ], + "showOutline": true, + "isRepeating": true, + "allowAddRemove": true, + "defaultRepetitions": 1, + "label": "Dynamic list", + "type": "dynamiclist", + "layout": { + "row": "Row_0kn6m8y", + "columns": null + }, + "id": "Field_033ey1v", + "path": "dynamiclist_lkkpkli" + } + ], + "showOutline": true, + "isRepeating": true, + "allowAddRemove": true, + "defaultRepetitions": 1, + "label": "Dynamic list", + "type": "dynamiclist", + "layout": { + "row": "Row_1d2g3ok", + "columns": null + }, + "id": "Field_1d4j6bh", + "path": "list" + } + ], + "$schema": "../../../form-json-schema/resources/schema.json", + "type": "default", + "id": "Form_1roxfho", + "schemaVersion": 16 +} \ No newline at end of file