Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { LegacyOptions } from './validation/schema'
import { getErrorMessage } from './errors/messages'
import { buildFieldSchema } from './field/schema'
import { calculateFinalSchema, updateFieldProperties } from './mutations'
import { addCustomJsonLogicOperations, removeCustomJsonLogicOperations } from './validation/json-logic'
import { addCustomJsonLogicOperations } from './validation/json-logic'
import { validateSchema } from './validation/schema'

export { LegacyOptions } from './validation/schema'
Expand Down Expand Up @@ -280,6 +280,10 @@ export function createHeadlessForm(
validateOptions(options)
const initialValues = options.initialValues || {}
const strictInputType = options.strictInputType || false
const customJsonLogicOps = options?.customJsonLogicOps

addCustomJsonLogicOperations(customJsonLogicOps)

// Make a new version of the schema with all the computed attrs applied, as well as the final version of each property (taking into account conditional rules)
const updatedSchema = calculateFinalSchema({
schema,
Expand All @@ -293,26 +297,17 @@ export function createHeadlessForm(
const isError = false

const handleValidation = (value: SchemaValue) => {
const customJsonLogicOps = options?.customJsonLogicOps

try {
addCustomJsonLogicOperations(customJsonLogicOps)
const updatedSchema = calculateFinalSchema({
schema,
values: value,
options: options.legacyOptions,
})

const updatedSchema = calculateFinalSchema({
schema,
values: value,
options: options.legacyOptions,
})
const result = validate(value, updatedSchema, options.legacyOptions)

const result = validate(value, updatedSchema, options.legacyOptions)
updateFieldProperties(fields, updatedSchema, schema)

updateFieldProperties(fields, updatedSchema, schema)

return result
}
finally {
removeCustomJsonLogicOperations(customJsonLogicOps)
}
return result
}

return {
Expand Down
8 changes: 0 additions & 8 deletions src/validation/json-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,3 @@ export function addCustomJsonLogicOperations(ops?: Record<string, (...args: any[
}
}
}

export function removeCustomJsonLogicOperations(ops?: Record<string, (...args: any[]) => any>) {
if (ops) {
for (const name of Object.keys(ops)) {
jsonLogic.rm_operation(name)
}
}
}
Loading