I have been attempting to do something like this, but with mantine form:
https://conform.guide/integration/nextjs
Where you can specify the onSubmit and the action on a form. Then, it will go through the process of both client and server side validation:
export function LoginForm() {
const [lastResult, action] = useFormState(login, undefined);
const [form, fields] = useForm({
// Sync the result of last submission
lastResult,
// Reuse the validation logic on the client
onValidate({ formData }) {
return parseWithZod(formData, { schema: loginSchema });
},
// Validate the form on blur event triggered
shouldValidate: 'onBlur',
shouldRevalidate: 'onInput',
});
return (
<form id={form.id} onSubmit={form.onSubmit} action={action} noValidate>
<div>
Unfortunately, I can't get it to work with mantine form. I have tried using form refs and calling things like formRef.current?.submit(); inside the form.onSubmit(), but nothing works. Does anyone have a working example for the latest version of Nextjs that shows mantine form working for both client and server validation?