react-component / react-component/field-form

Sharing the same `FormInstance` between multiple different forms

Open
#710 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. In the following code-sandbox form.validateFields() merges fields values from both forms. Form seems to work correctly.

  2. However, callbacks: onValuesChange, onFieldsChange, onFinish and onFinishFailed are only triggered for the last form. (they get overwritten here)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.