Replies: 1 comment 2 replies
-
|
你遇到的问题是 StepsForm 结合 form 实例(如 Form.useForm())时,如果下一步有必填项,点击“下一步”无法跳转。这是已知的 StepsForm bug,多个 issue 已确认:只要传递了 form 实例,且后续 Step 有 required 字段,就会阻断跳转,onCurrentChange 也不会触发,且没有报错提示(参考1)。 推荐做法:
示例代码: import { StepsForm, ProFormText } from '@ant-design/pro-components';
import { useRef } from 'react';
const formRef = useRef();
<StepsForm
formRef={formRef}
onFormChange={(name, values) => {
// 这里可以监听所有 step 的变化
console.log(name, values);
}}
>
<StepsForm.StepForm
name="step1"
onValuesChange={(changed, all) => {
// 只监听当前 step 的变化
console.log(changed, all);
}}
onFinish={async () => true}
>
<ProFormText name="a" label="A" rules={[{ required: true }]} />
</StepsForm.StepForm>
<StepsForm.StepForm
name="step2"
onFinish={async () => true}
>
<ProFormText name="b" label="B" rules={[{ required: true }]} />
</StepsForm.StepForm>
</StepsForm>这样你既能监听表单变化,也不会影响 StepsForm 的校验和跳转。 如果你一定要用 form 实例,建议只用 To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
https://codesandbox.io/p/sandbox/fen-bu-biao-dan-forked-czf7kq
Beta Was this translation helpful? Give feedback.
All reactions