Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Possibility to set `mode` for Form

## [3.10.0] - 2025-09-05

### Added
Expand Down
10 changes: 8 additions & 2 deletions src/lib/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactNode } from "react";
import { DeepPartial, FieldPath, FieldValues, Resolver, SubmitHandler, useForm, UseFormReturn } from "react-hook-form";
import { DeepPartial, FieldPath, FieldValues, Mode, Resolver, SubmitHandler, useForm, UseFormReturn } from "react-hook-form";
import { jsonIsoDateReviver } from "./helpers/dateUtils";
import { FormContext, FormContextProps } from "./context/FormContext";
import { AutoSubmitConfig, useAutoSubmit } from "./hooks/useAutoSubmit";
Expand All @@ -12,6 +12,11 @@ interface FormProps<T extends FieldValues> {
*/
onSubmit: SubmitHandler<T>;

/**
* The default validation mode of the form
*/
mode?: Mode;

/**
* the resolver for the validation
*/
Expand Down Expand Up @@ -70,13 +75,14 @@ const Form = <T extends FieldValues>({
formRef,
hideValidationMessages = false,
autoComplete,
mode,
}: FormProps<T>) => {
const revivedDefaultValues = defaultValues
? (JSON.parse(JSON.stringify(defaultValues), jsonIsoDateReviver) as DeepPartial<T>)
: defaultValues;

const disableAriaAutocomplete = autoComplete === "off";
const formMethods = useForm<T>({ resolver, defaultValues: revivedDefaultValues });
const formMethods = useForm<T>({ resolver, defaultValues: revivedDefaultValues, mode: mode });
const autoSubmitHandler = useAutoSubmit({ onSubmit, formMethods, autoSubmitConfig });

return (
Expand Down
Loading