Skip to content

Commit 89a2d0b

Browse files
author
Gianmarco Manni
committed
x
1 parent 9d538a2 commit 89a2d0b

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Possibility to set `mode` for Form
13+
1014
## [3.10.0] - 2025-09-05
1115

1216
### Added

src/lib/Form.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ReactNode } from "react";
2-
import { DeepPartial, FieldPath, FieldValues, Resolver, SubmitHandler, useForm, UseFormReturn } from "react-hook-form";
2+
import { DeepPartial, FieldPath, FieldValues, Mode, Resolver, SubmitHandler, useForm, UseFormReturn } from "react-hook-form";
33
import { jsonIsoDateReviver } from "./helpers/dateUtils";
44
import { FormContext, FormContextProps } from "./context/FormContext";
55
import { AutoSubmitConfig, useAutoSubmit } from "./hooks/useAutoSubmit";
@@ -12,6 +12,11 @@ interface FormProps<T extends FieldValues> {
1212
*/
1313
onSubmit: SubmitHandler<T>;
1414

15+
/**
16+
* The default validation mode of the form
17+
*/
18+
mode?: Mode;
19+
1520
/**
1621
* the resolver for the validation
1722
*/
@@ -70,13 +75,14 @@ const Form = <T extends FieldValues>({
7075
formRef,
7176
hideValidationMessages = false,
7277
autoComplete,
78+
mode,
7379
}: FormProps<T>) => {
7480
const revivedDefaultValues = defaultValues
7581
? (JSON.parse(JSON.stringify(defaultValues), jsonIsoDateReviver) as DeepPartial<T>)
7682
: defaultValues;
7783

7884
const disableAriaAutocomplete = autoComplete === "off";
79-
const formMethods = useForm<T>({ resolver, defaultValues: revivedDefaultValues });
85+
const formMethods = useForm<T>({ resolver, defaultValues: revivedDefaultValues, mode: mode });
8086
const autoSubmitHandler = useAutoSubmit({ onSubmit, formMethods, autoSubmitConfig });
8187

8288
return (

0 commit comments

Comments
 (0)