Skip to content

Commit

Permalink
feat: test
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyair committed Mar 14, 2024
1 parent c6ad1b5 commit 22ff548
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
17 changes: 15 additions & 2 deletions docs/examples/multiple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,23 @@ export default () => {
<>
<Form
form={form}
initialValues={{ one: '11', two: '22' }}
// initialValues={{ one: '11', two: '22' }}
onFinish={v => console.log('submit values', v)}
>
<Field<FieldType> names={['one', 'two']}>
<Field<FieldType>
names={['one', 'two']}
getValueProps={value => {
if (value) {
const two = form.getFieldValue('two');
return { value: [value, two] };
}
return { value: undefined };
}}
getValueFromEvent={values => {
form.setFields([{ name: 'two', value: values[1] }]);
return values[0];
}}
>
<RangeInput />
</Field>
{/* <Field<FieldType> name="two">
Expand Down
29 changes: 22 additions & 7 deletions src/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -683,15 +683,14 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
}
}

function WrapperField<Values = any>({ name, names, ...restProps }: FieldProps<Values>) {
function WrapperField<Values = any>({ name, names, children, ...restProps }: FieldProps<Values>) {
const fieldContext = React.useContext(FieldContext);
const listContext = React.useContext(ListContext);
const namePath = name !== undefined ? getNamePath(name) : undefined;
const namesPath = names !== undefined ? names.map(name => getNamePath(name)) : undefined;

let key: string = 'keep';
if (!restProps.isListField) {
key = `_${(namePath || namesPath || []).join('_')}`;
key = `_${(namePath || []).join('_')}`;
}

// Warning if it's a directly list field.
Expand All @@ -700,20 +699,36 @@ function WrapperField<Values = any>({ name, names, ...restProps }: FieldProps<Va
process.env.NODE_ENV !== 'production' &&
restProps.preserve === false &&
restProps.isListField &&
(namePath.length <= 1 || namesPath.length <= 1)
namePath.length <= 1
) {
warning(false, '`preserve` should not apply on Form.List fields.');
}

return (
<Field
key={key}
name={namePath}
isListField={!!listContext}
children={children}
{...restProps}
fieldContext={fieldContext}
/>
);
}

export default WrapperField;
function WrapperField2<Values = any>(props: FieldProps<Values>) {
const { name, names, children, ...restProps } = props;

if (names) {
return names.map((name, index) => {
return (

Check warning on line 722 in src/Field.tsx

View check run for this annotation

Codecov / codecov/patch

src/Field.tsx#L721-L722

Added lines #L721 - L722 were not covered by tests
<WrapperField
key={index}
{...restProps}
name={name}
children={index === 0 ? children : <div />}
/>
);
});
}
return <WrapperField {...props} />;
}
export default WrapperField2;

0 comments on commit 22ff548

Please sign in to comment.