gpt4 book ai didi

reactjs - Antd 表单远程提交

转载 作者:行者123 更新时间:2023-12-05 08:25:50 27 4
gpt4 key购买 nike

我想在antd表单外触发提交按钮

这是我的代码

<Form
{...layout}
name="basic"
initialValues={{
remember: true,
}}
onFinish={onFinish}
onFinishFailed={onFinishFailed}
>

<Form.Item
label="Username"
name="username"
rules={[
{
required: true,
message: 'Please input your username!',
},
]}
>
<Input />
</Form.Item>

<Form.Item {...tailLayout}>
// Submit button here works well
</Form.Item>
</Form>

我想要这个外部表单标签,请推荐

 <Button type="primary" htmlType="submit">
Submit
</Button>

最佳答案

你可以这样试试:

 const [form] = Form.useForm();

const handleFinish = (values) => {
console.log("values: ", values);
};

return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<MyForm form={form} onFinish={handleFinish} />
<Button onClick={() => form.submit()}>Submit</Button>
</div>
);
export const MyForm = ({ form, onFinish }) => {
return (
<Form
form={form}
onFinish={onFinish}
initialValues={{ username: "John Doe" }}
>
<Form.Item name="username">
<Input />
</Form.Item>
</Form>
);
};

Edit strange-currying-ttkv1

关于reactjs - Antd 表单远程提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61745864/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com