-
-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Submit form from external button (Form in Modal) #9380
Comments
Hello @X-Tender, we use GitHub issues to trace bugs or discuss plans of Ant Design. So, please don't ask usage questions here. You can try to ask questions on Stack Overflow or Segment Fault, then apply tag |
@yesmeck Unfortunately handling submit via JS is not not enough and submit on enter still does not work. <Form id="myForm">...</>
...
<Button form="myForm" key="submit" htmlType="submit">
Submit
</Button> See browser support |
same request,any solutions? |
I am just setting footer to null and put form inside the modal. It is very useful, when you want one form component for create and edit some entity. |
How about:
|
Why, guys, do you not like the hooks solution? const [isOpen, setIsOpen] = useState(false);
const [form] = Form.useForm();
const onSubmit = useCallback((values) => {
// do your staff with values
}, []);
const closePopup = useCallback(() => {
form.resetFields();
setIsOpen(false);
}, [form]);
<Modal
visible={isOpen}
onOk={form.submit}
onCancel={closePopup}
>
<Form
form={form}
onFinish={onSubmit}
/>
</Modal> |
@xr0master The hooks solution above works for many cases, but becomes cumbersome when you have several components between the Modal and the Form. You'll find yourself having to drill the props or use the context API. |
Exactly what I needed, since I had to connect form submission to buttons on parent (modal) |
How to get values in onOk (modal) instead onFinish (form). With this, it is possible to change the state of the Ok button to show loading |
What problem does this feature solve?
I have a Model with a form in it and would like to submit the form with the button which is in the footer of the modal.
There's no such method like "submit".
The Only way I see right now is to give the form an ID and getit via getElementById and call submit().
But I would like to trigger the validation process too.
How can I achieve it?
What does the proposed API look like?
callable submit method on the form
The text was updated successfully, but these errors were encountered: