From fa6e83877027d23cf746526ed7723fa96578c24e Mon Sep 17 00:00:00 2001 From: Valentin Serra Date: Wed, 6 Mar 2024 15:21:33 +0100 Subject: [PATCH] fix: properly pass `this` variable context to dynamic list elems Closes #1085 --- .../repeatRender/RepeatRenderManager.js | 28 ++++++------ .../form-js-viewer/test/spec/Form.spec.js | 36 ++++++++++++++++ .../test/spec/dynamic-list-variables.json | 43 +++++++++++++++++++ 3 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 packages/form-js-viewer/test/spec/dynamic-list-variables.json diff --git a/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js b/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js index bf6f6b757..6d34a508a 100644 --- a/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js +++ b/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js @@ -79,11 +79,11 @@ export class RepeatRenderManager { return ( <> - {displayValues.map((value, index) => + {displayValues.map((itemValue, itemIndex) => { const { - index, - value, + itemIndex, + itemValue, parentExpressionContextInfo, repeaterField, RowsRenderer, @@ -209,15 +209,15 @@ const RepetitionScaffold = (props) => { const elementProps = useMemo(() => ({ ...restProps, - indexes: { ...(indexes || {}), [ repeaterField.id ]: index } - }), [ index, indexes, repeaterField.id, restProps ]); + indexes: { ...(indexes || {}), [ repeaterField.id ]: itemIndex } + }), [ itemIndex, indexes, repeaterField.id, restProps ]); const localExpressionContextInfo = useMemo(() => ({ data: parentExpressionContextInfo.data, - this: value, + this: itemValue, parent: buildExpressionContext(parentExpressionContextInfo), - i: [ ...parentExpressionContextInfo.i , index + 1 ] - }), [ index, parentExpressionContextInfo, value ]); + i: [ ...parentExpressionContextInfo.i , itemIndex + 1 ] + }), [ itemIndex, parentExpressionContextInfo, itemValue ]); return !showRemove ? @@ -229,7 +229,7 @@ const RepetitionScaffold = (props) => { -