diff --git a/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js b/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js index cc255017f..4bbf7a4f0 100644 --- a/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js +++ b/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js @@ -34,7 +34,7 @@ export default class RepeatRenderManager { Repeater(props) { - const { RowsRenderer, indexes, useSharedState, ...restProps } = props; + const { RowsRenderer, indexes, useSharedState, variableContext: parentVariableContext, ...restProps } = props; const [ sharedRepeatState ] = useSharedState; @@ -63,10 +63,15 @@ export default class RepeatRenderManager { return ( <> - {displayValues.map((_, index) => { + {displayValues.map((value, index) => { const elementProps = { ...restProps, - indexes: { ...(indexes || {}), [ repeaterField.id ]: index } + indexes: { ...(indexes || {}), [ repeaterField.id ]: index }, + variableContext: { + this: value, + parent: parentVariableContext, + i: [ ...parentVariableContext.i , index ] + } }; return
diff --git a/packages/form-js-viewer/src/render/components/FormComponent.js b/packages/form-js-viewer/src/render/components/FormComponent.js index 57cdda8b3..a2af16efd 100644 --- a/packages/form-js-viewer/src/render/components/FormComponent.js +++ b/packages/form-js-viewer/src/render/components/FormComponent.js @@ -3,13 +3,15 @@ import FormField from './FormField'; import PoweredBy from './PoweredBy'; import useService from '../hooks/useService'; +import { useMemo } from 'preact/hooks'; +import { useFilteredFormData } from '../hooks'; const noop = () => {}; export default function FormComponent(props) { const form = useService('form'); - const { schema, properties } = form._getState(); + const { schema, properties, data } = form._getState(); const { ariaLabel } = properties; @@ -31,6 +33,14 @@ export default function FormComponent(props) { onReset(); }; + const filteredFormData = useFilteredFormData(); + + const variableContext = useMemo(() => ({ + parent: null, + this: filteredFormData, + i: [] + }), [ filteredFormData ]); + return (
diff --git a/packages/form-js-viewer/src/render/components/Label.js b/packages/form-js-viewer/src/render/components/Label.js index 2ca27e724..e2dbe8ee8 100644 --- a/packages/form-js-viewer/src/render/components/Label.js +++ b/packages/form-js-viewer/src/render/components/Label.js @@ -6,11 +6,12 @@ export default function Label(props) { const { id, label, + variableContext, collapseOnEmpty = true, required = false } = props; - const evaluatedLabel = useSingleLineTemplateEvaluation(label || '', { debug: true }); + const evaluatedLabel = useSingleLineTemplateEvaluation(label || '', { debug: true, variableContext }); return (