Only send edited data
Hello, I'm new to refine and was just testing it out by connecting it to my FeathersJS server. The issue I was running against is that refine sends the entire resource in the
PATCH
request.
So lets say I have a company that I want to just change the name of. When I press send, refine sends everything including fields I didn't change. This causes Feathers to throw an error that I am requesting to change fields I am not allowed to change.
Any solutions?11 Replies
deep-jade•2y ago
Hey @hego555 Check out this doc https://refine.dev/docs/faq/#how-can-i-change-the-form-data-before-submitting-it-to-the-api
FAQ | refine
How can I change the form data before submitting it to the API?
adverse-sapphire•2y ago
I will give this a shot, I am on Chakra UI if it matters. Im thinking I do a compare against the original values and see how that goes. Thanks!
Im actually unsure how to do this in Chakra
deep-jade•2y ago
Hey @hego555 A similar issue is descirbed here. I suggest a review this link. https://discord.com/channels/837692625737613362/1047868385767207003/1047875459326693486
adverse-sapphire•2y ago
The only thing confusing me is the auto generated chkra code doesn't have a
<form>
it has just <Edit>
wrapping the whole thing.deep-jade•2y ago
Yes
<form>
does not exist. Edit
component does submit
operation. Then you can follow a path;
adverse-sapphire•2y ago
Will try that. Appreciate the patience
Ok seems to make sense so far,
dirtyFields
seems to have all the properties that were edited. But they could still technically have the same value and it would consider them dirty. Will have to familiarize myself with how react hook form works. But much appreciated!
One funny thing I just noticed, the code inferrer makes a block like this for a number input
When you edit the value it returns a string type. You have to add valueAsNumber: true
to the register function options for this all to work correctly.
Not sure if this is indentedWow, you're right! Can you create an issue? @hego555 💯
adverse-sapphire•2y ago
Will do, also a similar issue with checkbox's have required set so it complains if the checkbox is not selected.
I'm not sure if this behavior is incorrect. We are giving the values as 'initialValue' for editing, this might make them 'dirty' immediately. Do you think there's an error in our code here: https://github.com/refinedev/refine/blob/next/packages/react-hook-form/src/useForm/index.ts#L94?
GitHub
refine/index.ts at next · refinedev/refine
Build your React-based CRUD applications, without constraints. - refine/index.ts at next · refinedev/refine
adverse-sapphire•2y ago
I would have to debug a bit to find the issue, but out of personal experience. Validating required against a checkbox never goes well. The generator maybe shouldnt be adding it in there.
adverse-sapphire•2y ago
https://github.com/refinedev/refine/issues/3550
The issue as requested. Thanks again for the help, I got what I wanted working like this in case anyone stumbles upon this
GitHub
[BUG] ChakraUIEditInferencer treats number fields as strings when e...
Describe the bug An example of the generated code is <FormControl mb="3" isInvalid={!!(errors as any)?.outstanding_amount}> <FormLabel>Outstanding Amou...