From 82df443ef7103f5ecc74eeb2a836050838ac05d5 Mon Sep 17 00:00:00 2001 From: Jack Greenlee Date: Thu, 29 Feb 2024 20:09:40 -0500 Subject: [PATCH] update scopedEval to return the result We want to use scopedEval to evaluate boolean expressions. It executes the code but doesn't return back the result unless we include 'return ...' in the body. With this quick change it returns the result of the evaluation and works on our inline conditionals. --- www/js/survey/enketo/conditionalSurveys.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/js/survey/enketo/conditionalSurveys.ts b/www/js/survey/enketo/conditionalSurveys.ts index c4fdcf08c..255b5821c 100644 --- a/www/js/survey/enketo/conditionalSurveys.ts +++ b/www/js/survey/enketo/conditionalSurveys.ts @@ -18,7 +18,7 @@ const conditionalSurveyFunctions = { * @example scopedEval('console.log(foo)', { foo: 'bar' }) */ const scopedEval = (script: string, scope: { [k: string]: any }) => - Function(...Object.keys(scope), script)(...Object.values(scope)); + Function(...Object.keys(scope), `return ${script}`)(...Object.values(scope)); // the first survey in the list that passes its condition will be returned export function getSurveyForTimelineEntry(