Skip to content

Commit 55e1996

Browse files
author
Adi Fatkhurozi
committed
fix: enhance override values with expression
1 parent 71a695e commit 55e1996

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/v2/logic/createForm.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,21 @@ const createForm = <TSchema>(props: ICreateFormProps<TSchema>) => {
403403
) => {
404404
if (!schema.overrides) return;
405405

406-
for (const { condition = true, expression, values } of schema.overrides) {
407-
if (!expression) {
408-
setValues(cloneDeep(values), { skipNotify: true });
409-
break;
410-
}
411-
406+
for (const { condition = true, expression, values, valuesExpression } of schema.overrides) {
412407
try {
413-
const result = parse(expression, { ...options.extraData }, schema.version);
414-
if (condition === !!result) {
415-
setValues(cloneDeep(values), { skipNotify: true });
408+
const skip = !expression;
409+
const result = skip ? true : parse(expression, { ...options.extraData }, schema.version);
410+
411+
if (skip || (condition === !!result)) {
412+
if (values) { setValues(cloneDeep(values), { skipNotify: true }); }
413+
if (valuesExpression) {
414+
for (const key in valuesExpression) {
415+
initValue(
416+
key,
417+
parse(valuesExpression[key], { ...options.extraData }, schema.version),
418+
);
419+
}
420+
}
416421
break;
417422
}
418423
} catch (error) {

src/v2/types/schema.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import { IDefaultProp, IExpressionString, IProp, ISchemaCore } from "./core";
33

44
// Field ===========================
55

6-
export interface IOverrideSchema extends ISchemaCore {
7-
comopnent: string;
8-
}
9-
106
export interface IOverrideField {
117
condition?: boolean;
128
expression?: IExpressionString;
13-
values: any;
9+
values?: any;
10+
valuesExpression?: Record<string, string>;
1411
}
1512

1613
export type IRule = {

0 commit comments

Comments
 (0)