fix: 表单项使用表达式默认值时联动计算结果无法触发校验问题 (#6104)

This commit is contained in:
RUNZE LU 2023-02-08 12:16:59 +08:00 committed by GitHub
parent 7c2fcdfb6a
commit a4e2890309
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -185,6 +185,7 @@ export function wrapControl<
required,
unique,
value,
isValueSchemaExp: isExpression(value),
rules: validations,
messages: validationErrors,
multiple,
@ -319,6 +320,7 @@ export function wrapControl<
id: props.$schema.id,
unique: props.$schema.unique,
value: props.$schema.value,
isValueSchemaExp: isExpression(props.$schema.value),
rules: props.$schema.validations,
multiple: props.$schema.multiple,
delimiter: props.$schema.delimiter,

View File

@ -581,14 +581,18 @@ export const FormStore = ServiceStore.named('FormStore')
item.resetValidationStatus();
}
// 验证过,或者是 unique 的表单项或者强制验证或者有远端校验api
/**
* 1. unique api
* 2. Schema的默认值为表达式
*/
if (
!item.validated ||
item.rules.equals ||
item.rules.equalsField ||
item.unique ||
forceValidate ||
!!item.validateApi
!!item.validateApi ||
item.isValueSchemaExp
) {
yield item.validate(self.data);
}

View File

@ -56,6 +56,8 @@ export const FormItemStore = StoreNode.named('FormItemStore')
unique: false,
loading: false,
required: false,
/** Schema默认值是否为表达式格式 */
isValueSchemaExp: types.optional(types.boolean, false),
tmpValue: types.frozen(),
emitedValue: types.frozen(),
rules: types.optional(types.frozen(), {}),
@ -216,6 +218,7 @@ export const FormItemStore = StoreNode.named('FormItemStore')
required,
unique,
value,
isValueSchemaExp,
rules,
messages,
delimiter,
@ -238,6 +241,7 @@ export const FormItemStore = StoreNode.named('FormItemStore')
required?: boolean;
unique?: boolean;
value?: any;
isValueSchemaExp: boolean;
rules?: string | {[propName: string]: any};
messages?: {[propName: string]: string};
multiple?: boolean;
@ -284,6 +288,7 @@ export const FormItemStore = StoreNode.named('FormItemStore')
typeof validateOnChange !== 'undefined' &&
(self.validateOnChange = !!validateOnChange);
typeof label === 'string' && (self.label = label);
self.isValueSchemaExp = !!isValueSchemaExp;
rules = {
...rules,