diff --git a/src/v2/logic/createForm.ts b/src/v2/logic/createForm.ts index 501be2a..66f3b2c 100644 --- a/src/v2/logic/createForm.ts +++ b/src/v2/logic/createForm.ts @@ -403,16 +403,21 @@ const createForm = (props: ICreateFormProps) => { ) => { if (!schema.overrides) return; - for (const { condition = true, expression, values } of schema.overrides) { - if (!expression) { - setValues(cloneDeep(values), { skipNotify: true }); - break; - } - + for (const { condition = true, expression, values, valuesExpression } of schema.overrides) { try { - const result = parse(expression, { ...options.extraData }, schema.version); - if (condition === !!result) { - setValues(cloneDeep(values), { skipNotify: true }); + const skip = !expression; + const result = skip ? true : parse(expression, { ...options.extraData }, schema.version); + + if (skip || (condition === !!result)) { + if (values) { setValues(cloneDeep(values), { skipNotify: true }); } + if (valuesExpression) { + for (const key in valuesExpression) { + initValue( + key, + parse(valuesExpression[key], { ...options.extraData }, schema.version), + ); + } + } break; } } catch (error) { diff --git a/src/v2/types/schema.ts b/src/v2/types/schema.ts index a13b7a8..3e2e5e6 100644 --- a/src/v2/types/schema.ts +++ b/src/v2/types/schema.ts @@ -3,14 +3,11 @@ import { IDefaultProp, IExpressionString, IProp, ISchemaCore } from "./core"; // Field =========================== -export interface IOverrideSchema extends ISchemaCore { - comopnent: string; -} - export interface IOverrideField { condition?: boolean; expression?: IExpressionString; - values: any; + values?: any; + valuesExpression?: Record; } export type IRule = {