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

Specific field error #323

Closed
wwwebman opened this issue Sep 30, 2018 · 3 comments
Closed

Specific field error #323

wwwebman opened this issue Sep 30, 2018 · 3 comments

Comments

@wwwebman
Copy link

wwwebman commented Sep 30, 2018

Is it possible get specific field error? Not first, not all, but specific?
For example, I have next schema:

const schema =  object().shape({
    name: string().required(),
    age: number()
      .required()
      .positive()
      .integer(),
    email: string()
      .email()
      .required(),
    website: string().url()

I want to get error related to email filed.

I know I can do it by adding { abortEarly: false } and looking for some path inner[0].path... But this approach has big disadvantage - re-call validation method on each blur/change event. So, maybe, it is not so painful in case of sync validation, but in case of API calls using yup.test it can be kick in the a**.

Looks like Formik has problem with it too:
jaredpalmer/formik#512

So, is there any ways to get specific error or plans to add such feature in the future?

@jquense
Copy link
Owner

jquense commented Sep 30, 2018

If you want to validate one path you can use schema.validateIn or use reach() to get the schema you wanna and call validate on that

@wwwebman
Copy link
Author

wwwebman commented Sep 30, 2018

Looks like plan, thanks.
I am also wounder about schema.validateAt which is do the same, I guess :) ?
There is a reason why schema.validateIn is not documented?

@jquense
Copy link
Owner

jquense commented Oct 1, 2018

I meant validateAt sorry, typo :P

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

No branches or pull requests

2 participants