From 1ad774142c4eef4155109a091f33a1cc4419677c Mon Sep 17 00:00:00 2001 From: Felipe Freitag Vargas Date: Thu, 8 Dec 2022 11:38:13 -0300 Subject: [PATCH] Add reValidateMode prop --- packages/remix-forms/src/createForm.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/remix-forms/src/createForm.tsx b/packages/remix-forms/src/createForm.tsx index ca953fe..f5cf8c0 100644 --- a/packages/remix-forms/src/createForm.tsx +++ b/packages/remix-forms/src/createForm.tsx @@ -98,6 +98,10 @@ type FormProps = ComponentMappings & { component?: FormComponent fetcher?: FetcherWithComponents mode?: keyof ValidationMode + reValidateMode?: keyof Pick< + ValidationMode, + 'onBlur' | 'onChange' | 'onSubmit' + > renderField?: RenderField> globalErrorsComponent?: ComponentOrTagName<'div'> buttonComponent?: ComponentOrTagName<'button'> @@ -143,6 +147,7 @@ function createForm({ component = DefaultComponent, fetcher, mode = 'onSubmit', + reValidateMode = 'onChange', renderField = defaultRenderField, fieldComponent, globalErrorsComponent: Errors = 'div', @@ -210,6 +215,7 @@ function createForm({ const form = useForm({ resolver: zodResolver(schema), mode, + reValidateMode, defaultValues, }) @@ -415,7 +421,7 @@ function createForm({ if (firstErroredField) { try { form.setFocus(firstErroredField as Path) - } catch { } + } catch {} } // eslint-disable-next-line react-hooks/exhaustive-deps }, [errorsProp, unparsedActionData])