fair-rose
fair-rose11mo ago

create refine, keep on page instead of navigate to list

how to keep on create page to countinue creating instead of navigate to list
16 Replies
kapa.ai
kapa.ai11mo ago
Hi @tuanna_. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In refine, you can manage the redirection behavior after creating a new record by using the useForm hook. When creating your Create Page, you can pass redirect: false to the useForm hook. This will disable the default redirection after a successful mutation, allowing you to stay on the create page and continue creating new records. Here is an example of how to do this:
import { useForm } from "@refinedev/core";

import { IPost } from "interfaces";

export const PostCreate: React.FC = () => {
const { formLoading, onFinish, redirect } = useForm<IPost>({
redirect: false,
});
};
import { useForm } from "@refinedev/core";

import { IPost } from "interfaces";

export const PostCreate: React.FC = () => {
const { formLoading, onFinish, redirect } = useForm<IPost>({
redirect: false,
});
};
In this example, redirect: false is passed to the useForm hook, which disables the default redirection after a successful mutation. This allows you to handle the redirection in your own way, such as staying on the create page to continue creating new records. For more information, you can refer to the refine documentation (https://refine.dev/docs/advanced-tutorials/forms/save-and-continue/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11mo ago
<@353701348463738885> kapa.ai is still learning and improving, please let us know how it did by reacting below
fair-rose
fair-rose11mo ago
@kapa.ai give full example
kapa.ai
kapa.ai11mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Sure, here is a more complete example of how you can use the useForm hook to stay on the create page after a successful mutation:
import { useForm } from "@refinedev/core";
import { IPost } from "interfaces";

export const PostCreate: React.FC = () => {
const { formLoading, onFinish, redirect } = useForm<IPost>({
redirect: false,
});

const handleSubmit = async (values: IPost) => {
const { data } = await onFinish(values);
// handle the response
};

return (
<form onSubmit={handleSubmit}>
{/* form fields here */}
<button type="submit">Submit</button>
</form>
);
};
import { useForm } from "@refinedev/core";
import { IPost } from "interfaces";

export const PostCreate: React.FC = () => {
const { formLoading, onFinish, redirect } = useForm<IPost>({
redirect: false,
});

const handleSubmit = async (values: IPost) => {
const { data } = await onFinish(values);
// handle the response
};

return (
<form onSubmit={handleSubmit}>
{/* form fields here */}
<button type="submit">Submit</button>
</form>
);
};
In this example, redirect: false is passed to the useForm hook, which disables the default redirection after a successful mutation. The handleSubmit function is then used to handle the form submission, where it calls the onFinish function with the form values. After the form is submitted, the page will not redirect to the list page, allowing you to stay on the create page and continue creating new records. Please note that you need to replace {/* form fields here */} with your actual form fields. For more information, you can refer to the refine documentation (https://refine.dev/docs/advanced-tutorials/forms/save-and-continue/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11mo ago
<@353701348463738885> kapa.ai is still learning and improving, please let us know how it did by reacting below
fair-rose
fair-rose11mo ago
@kapa.ai im using refine mui create basic view, how to make redirect false on create basic view
kapa.ai
kapa.ai11mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- In refine, the create function from the useCreate hook is used in the Basic Create View. To prevent redirection after a successful mutation, you can pass redirect: false to the useCreate hook. However, the information extracts provided do not contain a specific example of how to set redirect: false in the useCreate hook with the Basic Create View in refine. For more detailed information, you can refer to the refine documentation (https://refine.dev/docs). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11mo ago
<@353701348463738885> kapa.ai is still learning and improving, please let us know how it did by reacting below
fair-rose
fair-rose11mo ago
@kapa.ai im not using useForm, im using <Create><Create/> instead, how to set redirect false
kapa.ai
kapa.ai11mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- In the <Create> component of refine, you can control the redirection behavior by using the redirect prop. However, based on the information extracts provided, there's no specific example of setting redirect: false directly in the <Create> component. Typically, the redirect prop can be set to "show", "edit", "list", "create", or false. When set to false, it prevents the page from redirecting after the form is submitted. Here's a general example of how it might look:
<Create redirect={false}>
{/* form fields here */}
</Create>
<Create redirect={false}>
{/* form fields here */}
</Create>
Please note that this is a general example and might not work as expected because the exact usage is not provided in the information extracts. For more detailed information, you can refer to the refine documentation (https://refine.dev/docs). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11mo ago
<@353701348463738885> kapa.ai is still learning and improving, please let us know how it did by reacting below
fair-rose
fair-rose11mo ago
@kapa.ai it's not right, help me prevent redirect from Material UI API Components Basic Views Create <Create>
kapa.ai
kapa.ai11mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I'm sorry for the confusion, but based on the information extracts provided, there's no specific example or method mentioned on how to prevent redirection after a successful mutation using the <Create> component in the Material UI API of refine. For more detailed information, you can refer to the refine documentation (https://refine.dev/docs). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11mo ago
<@353701348463738885> kapa.ai is still learning and improving, please let us know how it did by reacting below
fair-rose
fair-rose11mo ago
@kapa.ai Autocomplete multiple