jquense / yup

Dead simple Object schema validation
MIT License
22.96k stars 936 forks source link

Specific field error #323

Closed wwwebman closed 6 years ago

wwwebman commented 6 years ago

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: https://github.com/jaredpalmer/formik/issues/512

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

jquense commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

I meant validateAt sorry, typo :P