Skip to content

Commit a465616

Browse files
committed
textExpression
1 parent cea44d3 commit a465616

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

apps/vps-web/src/app/custom-nodes-v2/form/VanillaFormCore.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,27 @@ export class VanillaFormCore {
262262
const text = document.createElement('p');
263263
text.id = component.id;
264264
text.className = 'text-gray-600';
265-
text.textContent = component.props?.text || '';
265+
text.textContent = component.props?.textExpression
266+
? this.getTextViaExpression(component.props?.textExpression)
267+
: component.props?.text || '';
266268
return text;
267269
}
270+
private getTextViaExpression(expression: string) {
271+
const compiledExpression = compileExpressionAsInfo(expression);
272+
const expressionFunction = (
273+
new Function('payload', `${compiledExpression.script}`) as unknown as (
274+
payload?: any
275+
) => any
276+
).bind(compiledExpression.bindings);
277+
return (
278+
runExpression(
279+
expressionFunction,
280+
this.payload,
281+
false,
282+
compiledExpression.payloadProperties
283+
) ?? ''
284+
).toString();
285+
}
268286
private getOptonsViaExpression(expression: string) {
269287
const compiledExpression = compileExpressionAsInfo(expression);
270288
const expressionFunction = (
@@ -276,7 +294,7 @@ export class VanillaFormCore {
276294
runExpression(
277295
expressionFunction,
278296
this.payload,
279-
false, // when True ... this fails when expression contains array indexes...
297+
false,
280298
compiledExpression.payloadProperties
281299
) ?? []
282300
);

examples-test-flows/learn-swedish.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
"id": "4360f032-9fbf-403b-af9f-f2dec001ddf6",
4141
"x": -3856.6332883515397,
4242
"y": 441.66501263880014,
43-
"width": 240.00002765556235,
44-
"height": 392.0000798973047,
43+
"width": 239.99984645555918,
44+
"height": 392.0000228764177,
4545
"nodeType": "Shape",
4646
"nodeInfo": {
4747
"type": "show-object",
@@ -52,15 +52,15 @@
5252
},
5353
{
5454
"id": "8f99faef-2ab2-4ea9-9bb4-3b26d5dc511e",
55-
"x": -3463.816290631263,
56-
"y": 347.6266773629999,
55+
"x": -3462.452335647429,
56+
"y": 348.5469448916196,
5757
"width": 483.1329126889236,
5858
"height": 490.94379671085414,
5959
"nodeType": "Shape",
6060
"nodeInfo": {
6161
"type": "form",
6262
"formValues": {
63-
"formJson": "{\n \"app\": {\n \"title\": \"Multi-step Form Example\",\n \"pages\": [\n {\n \"id\": \"personal-info\",\n \"title\": \"Personal Information\",\n \"route\": \"/personal\",\n \"isEndPage\": true,\n \"components\": [\n {\n \"type\": \"text\",\n \"id\": \"intro\",\n \"props\": {\n \"text\": \"Please provide your personal information\"\n }\n },\n {\n \"type\": \"input\",\n \"id\": \"name\",\n \"label\": \"Full Name\",\n \"validation\": {\n \"required\": true,\n \"minLength\": 2\n }\n },\n {\n \"type\": \"radio\",\n \"id\": \"question\",\n \"label\": \"Question\",\n \"props\": {\n \"optionsExpression\": \"o\"\n },\n \"validation\": {\n \"required\": true\n }\n },\n {\n \"type\": \"text\",\n \"id\": \"intro-add\",\n \"props\": {\n \"text\": \"lorem ipsum dolor sit amet, consectetur adipiscing elit. lorem ipsum dolor sit amet, consectetur adipiscing elit. lorem ipsum dolor sit amet, consectetur adipiscing elit. lorem ipsum dolor sit amet, consectetur adipiscing elit.\"\n }\n }\n ]\n }\n ]\n }\n}\n"
63+
"formJson": "{\n \"app\": {\n \"title\": \"Basic quiz\",\n \"pages\": [\n {\n \"id\": \"personal-info\",\n \"title\": \"Personal Information\",\n \"route\": \"/personal\",\n \"isEndPage\": true,\n \"components\": [\n {\n \"type\": \"text\",\n \"id\": \"intro\",\n \"props\": {\n \"textExpression\": \"sv\"\n }\n },\n {\n \"type\": \"radio\",\n \"id\": \"question\",\n \"label\": \"Question\",\n \"props\": {\n \"optionsExpression\": \"o\"\n },\n \"validation\": {\n \"required\": true\n }\n }\n ]\n }\n ]\n }\n}\n"
6464
},
6565
"fillColor": "black",
6666
"strokeColor": "white",
@@ -75,8 +75,8 @@
7575
"id": "5d3ca1b6-c787-416c-b5ec-61b3a3c2ddcd",
7676
"x": -2807.358803728899,
7777
"y": 435.0029362261489,
78-
"width": 240.00002765556235,
79-
"height": 55.999998282010935,
78+
"width": 240.00007742331653,
79+
"height": 104.00000624714835,
8080
"nodeType": "Shape",
8181
"nodeInfo": {
8282
"type": "show-object",
@@ -119,8 +119,8 @@
119119
"id": "a8e8565b-ea0d-4d23-a36a-8fe11446e943",
120120
"x": -938.3870024004736,
121121
"y": 86.93243020303709,
122-
"width": 120.00001382778117,
123-
"height": 56.00001360254896,
122+
"width": 120.0000613301946,
123+
"height": 55.99999753862592,
124124
"nodeType": "Shape",
125125
"nodeInfo": {
126126
"type": "show-input",
@@ -258,8 +258,8 @@
258258
},
259259
{
260260
"id": "81f7f7e4-c235-4a2c-9120-4099cc25ac54",
261-
"x": -3222.249834286801,
262-
"y": 593.0985757184269,
261+
"x": -3220.8858793029676,
262+
"y": 594.0188432470467,
263263
"endX": -2807.358803728899,
264264
"endY": 465.0029362261489,
265265
"startNodeId": "8f99faef-2ab2-4ea9-9bb4-3b26d5dc511e",
@@ -393,7 +393,7 @@
393393
},
394394
{
395395
"id": "8a9bf305-2989-4c5b-806b-26d422df2cc7",
396-
"x": -2567.3587760733367,
396+
"x": -2567.3587263055824,
397397
"y": 465.0029362261489,
398398
"endX": -2479.979994789843,
399399
"endY": 303.0296372811381,
@@ -438,10 +438,10 @@
438438
},
439439
{
440440
"id": "d4ffa17b-01ae-4a35-b0cc-d31bc3fa9ab5",
441-
"x": -3616.6332606959772,
441+
"x": -3616.6334418959805,
442442
"y": 471.66501263880014,
443-
"endX": -3463.816290631263,
444-
"endY": 593.0985757184269,
443+
"endX": -3462.452335647429,
444+
"endY": 594.0188432470467,
445445
"startNodeId": "4360f032-9fbf-403b-af9f-f2dec001ddf6",
446446
"endNodeId": "8f99faef-2ab2-4ea9-9bb4-3b26d5dc511e",
447447
"startThumbName": "output",

0 commit comments

Comments
 (0)