A form with consolidated error handling. The Form component extends Base UI's Form. It stacks its Field components in a column with consistent spacing.
Here is the component implementation code that you can copy to your project:
// https://devie-ui.com/components/form
// https://base-ui.com/react/components/form
import { Form as BaseForm } from "@base-ui/react/form";
import clsx from "clsx";
import styles from "./Form.module.scss";
function Form({ className, ...props }: Form.Props) {
return <BaseForm className={clsx(styles.form, className)} {...props} />;
}
namespace Form {
export type Props = Omit<BaseForm.Props, "className"> & {
className?: string;
};
export type State = BaseForm.State;
export type Values = BaseForm.Values;
export type SubmitEventDetails = BaseForm.SubmitEventDetails;
}
export default Form;Wrap each Field.Root in Form and pass onFormSubmit, which receives the values once every field is valid. Set validate on a Field.Root to check its value.
Pass an object to the errors prop on Form, keyed by field name. Field.Error shows these server errors alongside client errors.
Define the Zod schema with custom messages. Call safeParse, then z.flattenError() to build the errors object.
Base UI also documents TanStack Form and React Hook Form.