rare-sapphire
rare-sapphire8mo ago

saveButtonProps

what is the rest api call when saving ing saveButtonProps
2 Replies
kapa.ai
kapa.ai8mo ago
Hi @japope. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The saveButtonProps is a property provided by the useForm hook in Refine. It is used to customize the default button of the <Create> or <Edit> components that submit the form. However, the saveButtonProps itself does not directly make a REST API call. The actual API call is handled by the useForm hook and the <Create> or <Edit> components. When you click the "Save" button, the form data is submitted and an API request is sent. The saveButtonProps property handles the submission functionality of the form via the save button. If you want to modify the request before it's sent to the API, you can do so by using the onFinish function from the useForm hook. Here's an example:
const {
saveButtonProps,
handleSubmit,
refineCore: { onFinish }
} = useForm();

const onFinishHandler = (data: FieldValues) => {
onFinish({
...data,
test: 1
});
};

return (
<Create
saveButtonProps={{
...saveButtonProps,
onClick: (e: any) => {
handleSubmit(onFinishHandler, () => false)(e);
}
}}
>
const {
saveButtonProps,
handleSubmit,
refineCore: { onFinish }
} = useForm();

const onFinishHandler = (data: FieldValues) => {
onFinish({
...data,
test: 1
});
};

return (
<Create
saveButtonProps={{
...saveButtonProps,
onClick: (e: any) => {
handleSubmit(onFinishHandler, () => false)(e);
}
}}
>
In this example, the onFinishHandler function modifies the form data before it's submitted to the API. The handleSubmit function from useForm is then used to submit the form with the modified data. For more information, you can refer to the Refine documentation (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-form/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai8mo ago
<@465923409973477386> kapa.ai is still learning and improving, please let us know how it did by reacting below