Skip to content

Commit

Permalink
Add reValidateMode prop
Browse files Browse the repository at this point in the history
  • Loading branch information
felipefreitag committed Dec 8, 2022
1 parent 91dc530 commit 1ad7741
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/remix-forms/src/createForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ type FormProps<Schema extends FormSchema> = ComponentMappings & {
component?: FormComponent
fetcher?: FetcherWithComponents
mode?: keyof ValidationMode
reValidateMode?: keyof Pick<
ValidationMode,
'onBlur' | 'onChange' | 'onSubmit'
>
renderField?: RenderField<ObjectFromSchema<Schema>>
globalErrorsComponent?: ComponentOrTagName<'div'>
buttonComponent?: ComponentOrTagName<'button'>
Expand Down Expand Up @@ -143,6 +147,7 @@ function createForm({
component = DefaultComponent,
fetcher,
mode = 'onSubmit',
reValidateMode = 'onChange',
renderField = defaultRenderField,
fieldComponent,
globalErrorsComponent: Errors = 'div',
Expand Down Expand Up @@ -210,6 +215,7 @@ function createForm({
const form = useForm<SchemaType>({
resolver: zodResolver(schema),
mode,
reValidateMode,
defaultValues,
})

Expand Down Expand Up @@ -415,7 +421,7 @@ function createForm({
if (firstErroredField) {
try {
form.setFocus(firstErroredField as Path<SchemaType>)
} catch { }
} catch {}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [errorsProp, unparsedActionData])
Expand Down

0 comments on commit 1ad7741

Please sign in to comment.