diff --git a/docs/examples/names.tsx b/docs/examples/names.tsx index 0984d107..14e47cfa 100644 --- a/docs/examples/names.tsx +++ b/docs/examples/names.tsx @@ -39,15 +39,15 @@ export default () => { }} > { - // console.log('11', value); - // return { value: value }; - // }} - // getValueFromEvent={value => { - // console.log('2', value); - // return value; - // }} + // names={['start', 'end']} + // getValueProps={value => { + // console.log('11', value); + // return { value: value }; + // }} + // getValueFromEvent={value => { + // console.log('2', value); + // return value; + // }} > diff --git a/src/Field.tsx b/src/Field.tsx index cb13ac30..10c3ad3b 100644 --- a/src/Field.tsx +++ b/src/Field.tsx @@ -26,7 +26,6 @@ import { containsNamePath, defaultGetValueFromEvent, getNamePath, - getNamesPath, getValue, } from './utils/valueUtil'; @@ -70,8 +69,6 @@ export interface InternalFieldProps { dependencies?: NamePath[]; getValueFromEvent?: (...args: EventArgs) => StoreValue; name?: InternalNamePath; - names?: InternalNamePath[]; - noField?: boolean; normalize?: (value: StoreValue, prevValue: StoreValue, allValues: Store) => StoreValue; rules?: Rule[]; shouldUpdate?: ShouldUpdate; @@ -102,9 +99,8 @@ export interface InternalFieldProps { } export interface FieldProps - extends Omit, 'name' | 'names' | 'fieldContext'> { + extends Omit, 'name' | 'fieldContext'> { name?: NamePath; - names?: NamePath[]; } export interface FieldState { @@ -563,17 +559,9 @@ class Field extends React.Component implements F return getValue(store || getFieldsValue(true), namePath); }; - public getValues = (store?: Store) => { - const { getFieldsValue }: FormInstance = this.props.fieldContext; - const { names } = this.props; - return names.map(name => getValue(store || getFieldsValue(true), name)); - }; - public getControlled = (childProps: ChildProps = {}) => { const { name, - names, - noField, trigger, validateTrigger, getValueFromEvent, @@ -582,7 +570,6 @@ class Field extends React.Component implements F getValueProps, fieldContext, } = this.props; - if (noField) return; const mergedValidateTrigger = validateTrigger !== undefined ? validateTrigger : fieldContext.validateTrigger; @@ -590,11 +577,12 @@ class Field extends React.Component implements F const namePath = this.getNamePath(); const { getInternalHooks, getFieldsValue }: InternalFormInstance = fieldContext; const { dispatch } = getInternalHooks(HOOK_MARK); - const value = names ? this.getValues() : this.getValue(); + const value = this.getValue(); const mergedGetValueProps = getValueProps || ((val: StoreValue) => ({ [valuePropName]: val })); // eslint-disable-next-line @typescript-eslint/no-explicit-any const originTriggerFunc: any = childProps[trigger]; + const valueProps = name !== undefined ? mergedGetValueProps(value) : {}; // warning when prop value is function @@ -630,14 +618,12 @@ class Field extends React.Component implements F if (normalize) { newValue = normalize(newValue, value, getFieldsValue(true)); } - if (names) { - // eslint-disable-next-line @typescript-eslint/no-shadow - names.forEach((namePath, index) => { - dispatch({ type: 'updateValue', namePath, value: newValue[index] }); - }); - } else { - dispatch({ type: 'updateValue', namePath, value: newValue }); - } + + dispatch({ + type: 'updateValue', + namePath, + value: newValue, + }); if (originTriggerFunc) { originTriggerFunc(...args); @@ -696,11 +682,10 @@ class Field extends React.Component implements F } } -function WrapperField({ name, names, ...restProps }: FieldProps) { +function WrapperField({ name, ...restProps }: FieldProps) { const fieldContext = React.useContext(FieldContext); const listContext = React.useContext(ListContext); const namePath = name !== undefined ? getNamePath(name) : undefined; - const namesPath = getNamesPath(names); let key: string = 'keep'; if (!restProps.isListField) { @@ -718,30 +703,14 @@ function WrapperField({ name, names, ...restProps }: FieldProps - - {resetNames.map(item => ( - - {() => undefined} - - ))} - + ); } diff --git a/src/utils/valueUtil.ts b/src/utils/valueUtil.ts index 20fed2d4..eb64966a 100644 --- a/src/utils/valueUtil.ts +++ b/src/utils/valueUtil.ts @@ -16,10 +16,6 @@ export function getNamePath(path: NamePath | null): InternalNamePath { return toArray(path); } -export function getNamesPath(pathList: NamePath[] = []): InternalNamePath[] { - return pathList.map(path => toArray(path)); -} - export function cloneByNamePathList(store: Store, namePathList: InternalNamePath[]): Store { let newStore = {}; namePathList.forEach(namePath => {