Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing the same FormInstance between multiple different forms #710

Open
hophiphip opened this issue Jul 26, 2024 · 0 comments
Open

Sharing the same FormInstance between multiple different forms #710

hophiphip opened this issue Jul 26, 2024 · 0 comments

Comments

@hophiphip
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant