Closed tabrezm closed 3 months ago
Hey @tabrezm sorry for the issue! Looks like there should be a small update to the docs and also the distinction between the two onFinish
methods should be mentioned.
formProps.onFinish
uses the onFinish
internally and also includes two extra conditions, depending on the autoSubmitClose
and autoResetForm
props, it will call close()
and form.resetFields()
. One thing that is broken in the code sample is that onFinish
is an async function and needs to be awaited before moving on to the close()
call.
formProps.onFinish
awaits the onFinish
call and then continues with the close()
but in the code sample await
is missing and causes the issue with the unsaved changes notifier.
Let's keep this issue open and have the necessary changes to the docs to clear out misunderstandings. Let me know if the issue is resolved by adding a proper await
to the onFinish
call when you're using the onFinish
from the useModalForm
🙏
Yes, I believe that combination worked. Thanks for the speedy reply!
Is there a better/best practice to follow on using one approach over the other? Only needing to pass the formProps
is more convenient than passing around onFinish
and close
, and it seems like it's the higher-level encapsulation.
Describe the bug
I ran into something I believe is a doc issue (or possibly a bug) with
useModalForm
from@refinedev/antd
.I implemented a form where I need to do a file upload upon submitting the form, so I provided my own method to
onFinish
in theForm
component. Based on the doc, I thought I could callonFinish
and thenclose
. But I ran into the following behaviors:I realized after much trial and error that the right method to call is not
onFinish
fromuseModalForm
, butonFinish
from theformProps
. Furthermore, I don't need to call close sinceonFinish
seems to close the dialog already. So a couple questions:const { close, modalProps, formProps, onFinish } = useModalForm();
const onFinishHandler = (values) => { // do some work onFinish(values); close(); };
// ---
return ( <Modal {...modalProps}> <Form {...formProps} onFinish={onFinishHandler} layout="vertical">