How to modify json before sending it to backend API
I have a Form.Item that is only for UI purposes. This is getting included in the backend JSON request automatically. How can I suppress/filter certain elements from being included in the backend JSON request?
I have tried the following without success
- hidden attribute in antd Form hides from the UI - Not what i want
- included transform rules in Form.Item - throws an error in asyncvalidator saying "key" is not a valid undefined
- Not able to change TVariables variable in create dataprovider method
Any idea on how I can achieve this without changing the backend provider API ?
7 Replies
frail-apricot•2y ago
Hey @rapurush check this doc https://refine.dev/docs/api-reference/antd/hooks/form/useForm/#how-can-i-change-the-form-data-before-submitting-it-to-the-api i think this will solve your issue 🚀
useForm | refine
useForm is used to manage forms. It is based on Antd Form and refine useForm to supports all the features of these packages and adds some additional features.
genetic-orange•2y ago
@aliemirs how can I achieve this in Material UI?
frail-apricot•2y ago
@Hanif Mianjee assuming you're using
@pankod/refine-react-hook-form
here's the docs https://refine.dev/docs/packages/documentation/react-hook-form/useForm/#how-can-i-change-the-form-data-before-submitting-it-to-the-apiuseForm | refine
The @pankod/refine-react-hook-form adapter allows you to integrate the React Hook Form library with refine, enabling you to manage your forms in a headless manner. This adapter supports all of the features of both React Hook Form and refine's useForm hook, and you can use any of the React Hook Form examples as-is by copying and pasting them into...
frail-apricot•2y ago
But the API is same basically since it's a feature of the
@pankod/refine-core
's useForm
and the other packages are just extending itgenetic-orange•2y ago
Thanks @aliemirs I will try this doc
frail-apricot•2y ago
Happy to help, do not hesitate to send a new post if you encounter any issues 🚀
genetic-orange•2y ago
Issue resolved, thanks @aliemirs @rapurush