fix: formItem 的 config 方法中不应该还有 onChange 逻辑,在 wrapControl 的 didMount 已经处理了 (#2277)

This commit is contained in:
liaoxuezhi 2021-07-14 20:18:17 +08:00 committed by GitHub
parent ad20763066
commit ccef657405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 92 deletions

View File

@ -153,28 +153,25 @@ export function wrapControl<
this.model = model;
// @issue 打算干掉这个
formItem?.addSubFormItem(model);
model.config(
{
id,
type,
required,
unique,
value,
rules: validations,
messages: validationErrors,
multiple,
delimiter,
valueField,
labelField,
joinValues,
extractValue,
selectFirst,
autoFill,
clearValueOnHidden,
validateApi
},
onChange
);
model.config({
id,
type,
required,
unique,
value,
rules: validations,
messages: validationErrors,
multiple,
delimiter,
valueField,
labelField,
joinValues,
extractValue,
selectFirst,
autoFill,
clearValueOnHidden,
validateApi
});
// issue 这个逻辑应该在 combo 里面自己实现。
if (
@ -263,27 +260,24 @@ export function wrapControl<
props.$schema
)
) {
model.config(
{
required: props.$schema.required,
id: props.$schema.id,
unique: props.$schema.unique,
value: props.$schema.value,
rules: props.$schema.validations,
multiple: props.$schema.multiple,
delimiter: props.$schema.delimiter,
valueField: props.$schema.valueField,
labelField: props.$schema.labelField,
joinValues: props.$schema.joinValues,
extractValue: props.$schema.extractValue,
messages: props.$schema.validationErrors,
selectFirst: props.$schema.selectFirst,
autoFill: props.$schema.autoFill,
clearValueOnHidden: props.$schema.clearValueOnHidden,
validateApi: props.$schema.validateApi
},
props.onChange
);
model.config({
required: props.$schema.required,
id: props.$schema.id,
unique: props.$schema.unique,
value: props.$schema.value,
rules: props.$schema.validations,
multiple: props.$schema.multiple,
delimiter: props.$schema.delimiter,
valueField: props.$schema.valueField,
labelField: props.$schema.labelField,
joinValues: props.$schema.joinValues,
extractValue: props.$schema.extractValue,
messages: props.$schema.validationErrors,
selectFirst: props.$schema.selectFirst,
autoFill: props.$schema.autoFill,
clearValueOnHidden: props.$schema.clearValueOnHidden,
validateApi: props.$schema.validateApi
});
}
if (model && typeof props.value !== 'undefined') {

View File

@ -200,51 +200,43 @@ export const FormItemStore = StoreNode.named('FormItemStore')
const form = self.form as IFormStore;
const dialogCallbacks = new SimpleMap<(result?: any) => void>();
function config(
{
required,
unique,
value,
rules,
messages,
delimiter,
multiple,
valueField,
labelField,
joinValues,
extractValue,
type,
id,
selectFirst,
autoFill,
clearValueOnHidden,
validateApi
}: {
required?: boolean;
unique?: boolean;
value?: any;
rules?: string | {[propName: string]: any};
messages?: {[propName: string]: string};
multiple?: boolean;
delimiter?: string;
valueField?: string;
labelField?: string;
joinValues?: boolean;
extractValue?: boolean;
type?: string;
id?: string;
selectFirst?: boolean;
autoFill?: any;
clearValueOnHidden?: boolean;
validateApi?: boolean;
},
onChange?: (
value: any,
name: string,
submit?: boolean,
changePristine?: boolean
) => void
) {
function config({
required,
unique,
value,
rules,
messages,
delimiter,
multiple,
valueField,
labelField,
joinValues,
extractValue,
type,
id,
selectFirst,
autoFill,
clearValueOnHidden,
validateApi
}: {
required?: boolean;
unique?: boolean;
value?: any;
rules?: string | {[propName: string]: any};
messages?: {[propName: string]: string};
multiple?: boolean;
delimiter?: string;
valueField?: string;
labelField?: string;
joinValues?: boolean;
extractValue?: boolean;
type?: string;
id?: string;
selectFirst?: boolean;
autoFill?: any;
clearValueOnHidden?: boolean;
validateApi?: boolean;
}) {
if (typeof rules === 'string') {
rules = str2rules(rules);
}
@ -281,10 +273,6 @@ export const FormItemStore = StoreNode.named('FormItemStore')
clearError('builtin');
self.validated = false;
}
if (value !== void 0 && self.value === void 0) {
onChange?.(value, self.name, false, true);
}
}
function focus() {