The Form component extends Base UI's Form. It coordinates validation across multiple form controls like Field, Checkbox, and CheckboxGroup. The Form validates all fields before calling onFormSubmit.
Here is the component implementation code that you can copy to your project:
Use the validate prop on Field.Root to define custom validation rules. Set validationMode to control when validation runs: "onBlur" validates when the field loses focus, "onChange" validates on every keystroke.
Client-side validation (via the validate prop) provides instant feedback, while server-side validation catches issues that can only be verified remotely, like checking if a code is valid.
Pass server errors to the errors prop on Form as an object mapping field names to error messages. Field.Error automatically displays both client-side and server errors.
If you use Zod for validation, define your schema with custom error messages, then use safeParse and error.flatten() to convert validation errors into the format expected by Form's errors prop.
Base UI can also integrate with TanStack Form and React Hook Form if you prefer to use these libraries to manage your form states.