Form: Transform data before submit
Is it possible to transform data before submit with a useForm + antd ?
5 Replies
Hi @Nicolas Bourdin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, it is possible to transform or modify the form data before submitting it to the API using
useForm
with Ant Design in Refine. You can achieve this by creating a custom onFinish
function where you modify the form data as needed. Here is an example:
In this example, the values received from the user in two separate inputs, name
and surname
, are combined and sent to the API as fullName
source (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-form#how-can-i-change-the-form-data-before-submitting-it-to-the-api).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@798191015391395866> kapa.ai is still learning and improving, please let us know how it did by reacting below
subsequent-cyanOP•14mo ago
give me an example which transform a boolean in a nullable (if not checked) or date now (if checked) before submit @kapa.ai
give me an example which transform a boolean in a nullable (if not checked) or date now (if checked) before submit @kapa.ai
Let me check the knowledge base for you. One moment! :books:
----------------------
Sure, here is an example of how you can transform a boolean value into a nullable (if not checked) or the current date (if checked) before submitting the form:
In this example, the
handleOnFinish
function checks if the checkbox is checked. If it is, it sets the value to the current date. If it's not checked, it sets the value to null. This transformed value is then passed to the onFinish
function from useForm
, which submits the form data to the API.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@798191015391395866> kapa.ai is still learning and improving, please let us know how it did by reacting below