Skip to content

Ref not propagating to errors object when resolver is used #77

@TMUND

Description

@TMUND

Hello react-hook-form,

First of all, thank you for a great form library! However, I am noticing an issue with propagating the ref of the input that threw the error when I use the Joi resolver in my project.

According to the docs here: https://react-hook-form.com/api#errors I should receive type, types, message and ref from the errors object. I have confirmed that this is true when I don't use a resolver and construct my field validation manually like so:

console.log(errors);

<input
  ref={register({ required: 'custom required message' })}
  type="email"
  name="email"
  ...etc.
/>

Screen Shot 2020-11-16 at 11 56 19 AM

...but when I construct my field validations via Joi I only receive the message and type properties from the errors object. My code looks something like this:

const { register, errors } = useForm<FormValues>({
  resolver: joiResolver(validationSchema.current),
});

console.log(errors);

<input
  ref={register}
  type="email"
  name="email"
  ...etc.
/>

...and my response looks like this:
Screen Shot 2020-11-16 at 11 55 28 AM

How do I ensure that the ref of the input which threw the error comes through in the useForm errors object?

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions