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

Deprecate validation in <Form> #1434

Closed
Tobbe opened this issue Nov 4, 2020 · 3 comments
Closed

Deprecate validation in <Form> #1434

Tobbe opened this issue Nov 4, 2020 · 3 comments

Comments

@Tobbe
Copy link
Member

Tobbe commented Nov 4, 2020

The <Form> component takes a validation prop, but it's really so much more. It's passed straight in to react-hook-form's useForm and can so take all the available config options, not just validation related.

This should be reflected in the name of the variable. Something like formOptions would fit with the already existing formMethods. The names of the respective TS types are UseFormOptions and UseFormMethods.

The prop is used in the tutorial like this:

// web/src/pages/ContactPage/ContactPage.js

<Form onSubmit={onSubmit} validation={{ mode: 'onBlur' }}>

So it does read very well. Better than formOptions={{ mode: 'onBlur' }} would.

Going forward I see two options

  1. Deprecate validation and point people towards formOptions instead
  2. Keep validation, but make it only take the mode parameter (possibly also reValidateMode as that also has to do with validation). And then additionally add formOptions for controlling everything.

This is the list of everything you can pass to useForm

const { register } = useForm({
  mode: 'onSubmit',
  reValidateMode: 'onChange',
  defaultValues: {},
  resolver: undefined,
  context: undefined,
  criteriaMode: "firstError",
  shouldFocusError: true,
  shouldUnregister: true,
})
@thedavidprice
Copy link
Contributor

This is a great idea. To keep it backwards compatible, I'd like us to go with your recommend option 2.

Will see if we can link this together with #2270

@jtoar
Copy link
Contributor

jtoar commented Aug 26, 2021

Note that the names of the types have changed: https://github.com/react-hook-form/react-hook-form/blob/master/CHANGELOG.md#changes-13

  • UseFormOptions -> UseFormProps
  • UseFormMethods -> UseFormReturn

@thedavidprice
Copy link
Contributor

@jtoar Will the final implementation of #3376 close this one?

@jtoar jtoar closed this as completed Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants