other-emerald•9mo ago
Transform Antd useForm Values on Submission
How can I transform the user's entered values before they are submitted with useForm from refinedev/antd?
5 Replies
Hi @obelisk291. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To transform the user's entered values before they are submitted using
useForm from @refinedev/antd, you can utilize the onFinish function. Here's how you can do it:
1. First, import the necessary components and hooks:
2. In your component, use the useForm hook:
3. Create a custom handleOnFinish function to transform the values:
4. Use this custom function in your form's onFinish prop:
Here's a complete example:
In this example, the name and surname fields are combined into a fullName field before submission.
You can find more information about this in the Refine Ant Design useForm documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1257731147509661728> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
other-emeraldOP•9mo ago
@kapa.ai Cannot find name 'onFinish'.ts(2304)
Let me check the knowledge base for you again. One moment! :books:
----------------------
I apologize for the confusion in my previous answer. It seems I made an error in explaining the usage of
onFinish. Let me provide a correct and more detailed explanation based on the official Refine documentation.
The error "Cannot find name 'onFinish'.ts(2304)" occurs because onFinish is not directly available from the useForm hook in @refinedev/antd. Instead, it's part of the formProps object. Here's how you can correctly transform the form values before submission:
1. First, import the necessary components and hooks:
2. In your component, use the useForm hook:
3. Create a custom handleOnFinish function to transform the values:
4. Use this custom function in your form's onFinish prop, combining it with the original formProps.onFinish:
Here's the complete, corrected example:
This approach ensures that the form values are transformed before being submitted, while still utilizing the onFinish function provided by formProps.
For more information on using useForm and handling form submissions in Refine with Ant Design, you can refer to the Refine Ant Design useForm documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1257731147509661728> Kapa.ai is still learning and improving, please let me know how I did by reacting below.