Pass extra parameters in useForm

How can I pass extra parameters during the save operations in the antd useForm hook? For example, I want to pass all of the form data and then another parameter called "entityTypeId".
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @MesbearizingMeat. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- You can pass extra parameters during the save operations in the useForm hook by modifying the onFinish function. In the onFinish function, you can add your extra parameters to the values object. Here is an example:
import { Create, useForm } from "@refinedev/antd";
import { Form, Input } from "antd";
import React from "react";

export const UserCreate: React.FC = () => {
const { formProps, saveButtonProps, onFinish } = useForm();

const handleOnFinish = (values) => {
onFinish({
...values,
entityTypeId: 'yourEntityTypeId',
});
};

return (
<Create saveButtonProps={saveButtonProps}>
<Form {...formProps} onFinish={handleOnFinish} layout="vertical">
<Form.Item label="Name" name="name">
<Input />
</Form.Item>
<Form.Item label="Surname" name="surname">
<Input />
</Form.Item>
</Form>
</Create>
);
};
import { Create, useForm } from "@refinedev/antd";
import { Form, Input } from "antd";
import React from "react";

export const UserCreate: React.FC = () => {
const { formProps, saveButtonProps, onFinish } = useForm();

const handleOnFinish = (values) => {
onFinish({
...values,
entityTypeId: 'yourEntityTypeId',
});
};

return (
<Create saveButtonProps={saveButtonProps}>
<Form {...formProps} onFinish={handleOnFinish} layout="vertical">
<Form.Item label="Name" name="name">
<Input />
</Form.Item>
<Form.Item label="Surname" name="surname">
<Input />
</Form.Item>
</Form>
</Create>
);
};
In this example, entityTypeId is the extra parameter that you want to pass. Replace 'yourEntityTypeId' with the actual value you want to pass. This code is based on the example provided in the Refine documentation (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: ----------------------
kapa.ai
kapa.ai2mo ago
<@224018850419572736> kapa.ai is still learning and improving, please let us know how it did by reacting below