react-component / react-component/field-form
Sharing the same `FormInstance` between multiple different forms
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1k
- Forks
- 286
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 1
Description
Does sharing the same FormInstance between multiple <Form /> components considered correct?
Example:
function SampleWithError() {
const [form] = Form.useForm();
return (
<>
<Form form={form}>
<Field name="one"></Field>
</Form>
<Form form={form}>
<Field name="two"></Field>
</Form>
<button onClick={async () => {
console.log(await form.validateFields());
}}>
Validate
</button>
</>
)
}
Also, some of my observations on form behavior for this particular case:
-
In the following code-sandbox
form.validateFields()merges fields values from both forms. Form seems to work correctly. -
However, callbacks:
onValuesChange,onFieldsChange,onFinishandonFinishFailedare only triggered for the last form. (they get overwritten here)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the shared-instance behavior in the linked CodeSandbox, then inspect src/Form.tsx around line 94 where callbacks are overwritten. Compare validation and callback behavior across both forms, and define completion as a tested, documented resolution for sharing one FormInstance between multiple Form components.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100