ant-design / ant-design/pro-components

ModalForm 中获取 form 实例时会报错 Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?

Open
#9,628 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.8k
Forks
1.4k
Avg merge
10h 44m
Merged PRs (30d)
3

Description

如果 ModalForm 封装为 组件时,在组件里使用

`
// 这步不会报错
const [modalForm] = Form.useForm();

// 设置初始化字段值会提醒
modalForm.setFieldsValue(data)
`
`
Instance created by `useForm` is not connected to any Form element. Forget to pass `form` prop?
`

会提醒上面的报错,但是值也会初始化。

Contributor guide

Open the contributing guide

Research direction

Start at the ModalForm entry point and reproduce the reported case with Form.useForm and modalForm.setFieldsValue(data) inside a wrapped component. Check why the form instance is not connected when the initial values are set; done means the values still initialize without the connection warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.