fix use of loop item in javascript bindings

This commit is contained in:
Peter Clement 2022-06-23 16:09:35 +01:00
parent fadd4292ad
commit 0dcd7f3d63
1 changed files with 19 additions and 4 deletions

View File

@ -1,5 +1,10 @@
const { getTable } = require("../api/controllers/table/utils")
const { findHBSBlocks } = require("@budibase/string-templates")
const {
findHBSBlocks,
decodeJSBinding,
isJSBinding,
encodeJSBinding,
} = require("@budibase/string-templates")
/**
* When values are input to the system generally they will be of type string as this is required for template strings.
@ -77,11 +82,21 @@ exports.getError = err => {
}
exports.substituteLoopStep = (hbsString, substitute) => {
let blocks = findHBSBlocks(hbsString)
let blocks = []
let checkForJS = isJSBinding(hbsString)
if (checkForJS) {
hbsString = decodeJSBinding(hbsString)
blocks.push(hbsString)
} else {
blocks = findHBSBlocks(hbsString)
}
for (let block of blocks) {
let oldBlock = block
block = block.replace(/loop/, substitute)
hbsString = hbsString.replace(new RegExp(oldBlock, "g"), block)
if (checkForJS) {
hbsString = encodeJSBinding(block)
} else {
hbsString = block
}
}
return hbsString