Skip to content

Commit e05a913

Browse files
feat: support nested objects in the x-jsf-logic attributes
1 parent c24d5e7 commit e05a913

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

next/src/field/schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ export function buildFieldSchema(
298298

299299
// Clone the schema to avoid mutating the original, as we'll be adding computed attributes to it
300300
let schemaCopy = safeDeepClone(schema)
301-
// schemaCopy['x-jsf-presentation'] = schemaCopy?.['x-jsf-presentation'] || {}
302301

303302
const computedSchema = jsonLogicContext ? buildSchemaBasedOnComputedAttrs(schema, jsonLogicContext) : undefined
304303

next/src/validation/json-logic.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,18 @@ function computeObjectValues(
201201

202202
const computedObjectValues: Record<string, string> = {}
203203

204-
Object.entries(value).forEach(([key, message]) => {
205-
let computedMessage = message
206-
if (containsHandlebars(message)) {
207-
computedMessage = interpolate(message, jsonLogicContext)
204+
Object.entries(value).forEach(([key, value]) => {
205+
let computedMessage = value
206+
// If the message contains handlebars, interpolate it
207+
if (containsHandlebars(value)) {
208+
computedMessage = interpolate(value, jsonLogicContext)
209+
}
210+
else {
211+
// Check if the object value is the name of a computed value and if so, calculate it
212+
const rule = jsonLogicContext?.schema?.computedValues?.[value]?.rule
213+
if (rule) {
214+
computedMessage = jsonLogic.apply(rule, replaceUndefinedAndNullValuesWithNaN(jsonLogicContext.value as ObjectValue))
215+
}
208216
}
209217
computedObjectValues[key] = computedMessage
210218
})

0 commit comments

Comments
 (0)