fix: field loss enum (#667)

This commit is contained in:
SemmyWong 2022-07-25 09:41:32 +08:00 committed by GitHub
parent 73d4b15040
commit 9f7f482aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -1,11 +1,11 @@
import { Field } from '@formily/core';
import { connect, useField, useFieldSchema } from '@formily/react';
import { merge } from '@formily/shared';
import { concat } from 'lodash';
import React, { useEffect } from 'react';
import { useCompile, useComponent, useFormBlockContext } from '..';
import { CollectionFieldProvider } from './CollectionFieldProvider';
import { useCollectionField } from './hooks';
import { concat } from 'lodash';
// TODO: 初步适配
const InternalField: React.FC = (props) => {
@ -40,7 +40,7 @@ const InternalField: React.FC = (props) => {
setFieldProps('description', uiSchema.description);
setFieldProps('initialValue', uiSchema.default);
if (!field.validator && (uiSchema['x-validator'] || fieldSchema['x-validator'])) {
const concatSchema = concat([], uiSchema['x-validator'] || [], fieldSchema['x-validator'] || [])
const concatSchema = concat([], uiSchema['x-validator'] || [], fieldSchema['x-validator'] || []);
field.validator = concatSchema;
}
if (fieldSchema['x-disabled'] === true) {
@ -69,7 +69,7 @@ const InternalField: React.FC = (props) => {
if (!uiSchema) {
return null;
}
return React.createElement(component, props, props.children);
};

View File

@ -1,5 +1,6 @@
import { Field } from '@formily/core';
import { connect, useField, useFieldSchema } from '@formily/react';
import { merge } from '@formily/shared';
import { Cascader, Select, Space } from 'antd';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
@ -18,7 +19,6 @@ const DYNAMIC_TIME_REG = /\{\{\s*currentTime\s*\}\}/;
const InternalField: React.FC = (props) => {
const field = useField<Field>();
const fieldSchema = useFieldSchema();
const { name, interface: interfaceType, uiSchema } = useCollectionField();
const component = useComponent(uiSchema?.['x-component']);
@ -59,9 +59,10 @@ const InternalField: React.FC = (props) => {
}
setRequired();
// @ts-ignore
// field.dataSource = uiSchema.enum;
// const originalProps = compile(uiSchema['x-component-props']) || {};
// const componentProps = merge(originalProps, field.componentProps || {});
field.dataSource = uiSchema.enum;
const originalProps = compile(uiSchema['x-component-props']) || {};
const componentProps = merge(originalProps, field.componentProps || {});
field.componentProps = componentProps;
// field.component = [component, componentProps];
}, [JSON.stringify(uiSchema)]);
if (!uiSchema) {