Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reValidateMode prop #125

Merged
merged 1 commit into from
Dec 8, 2022
Merged
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
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<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the casing in revalidateMode is more of a common sense even though it might be wrong =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that too, but RHF uses this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know! Thanks

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