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

Create resolver for react-hook-form #59

Open
darkowic opened this issue Mar 23, 2021 · 1 comment
Open

Create resolver for react-hook-form #59

darkowic opened this issue Mar 23, 2021 · 1 comment
Labels

Comments

@darkowic
Copy link
Contributor

darkowic commented Mar 23, 2021

React hook form is a popular form validation library that supports forms schema resolving by resolver API (https://github.com/react-hook-form/resolvers). Resolvers are already implemented for validators like yup, superstruct, etc which are natural competitors for this library.

For me, it seems like a common use-case to use schema definitions to validate forms. But to do that we need to first support reporting errors per object attribute (#13).

Resolver draft (trying to do it here):

export const schemaResolver = (schema) => {
  const validator = validate(schema);

  return (values) => {
    try {
      return {
        values: validator(values),
        errors: {}
      };
    } catch (e) {
      const errors = /* get errors per schema attribute, each error should be a string */

      return {
        values: {},
        errors: errors
      };
    }
  };
}
@typeofweb
Copy link
Member

Blocked by #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants