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

Describe not working on conditionnal validation for yup.array() #1920

Closed
Dauflo opened this issue Feb 23, 2023 · 4 comments
Closed

Describe not working on conditionnal validation for yup.array() #1920

Dauflo opened this issue Feb 23, 2023 · 4 comments

Comments

@Dauflo
Copy link

Dauflo commented Feb 23, 2023

Describe the bug
When you add when() on a yup.array(), the condition will never get described when calling describe method on the validation schema.

To Reproduce

import * as yup from 'yup'

const validationSchema = yup.object({
    foo: yup.boolean(),
    bar: yup.array().of(yup.string()).when('foo', {
        is: true,
        then: (schema) => schema.min(1)
    }),
    baz: yup.string().when('foo', {
        is: true,
        then: (schema) => schema.required()
    })
})

console.log(validationSchema.describe({ value: { foo: false, bar: [] } }).fields['bar'].tests)
console.log(validationSchema.describe({ value: { foo: true, bar: [] } }).fields['bar'].tests)
console.log(validationSchema.describe({ value: { foo: true, bar: ['bar'] } }).fields['bar'].tests)

console.log(validationSchema.describe({ value: { foo: false } }).fields['baz'].tests)
console.log(validationSchema.describe({ value: { foo: true } }).fields['baz'].tests)
console.log(validationSchema.describe({ value: { foo: true, baz: 'baz' } }).fields['baz'].tests)

Output

[]
[]
[]
[]
[ { name: 'required', params: undefined } ]
[ { name: 'required', params: undefined } ]

Expected behavior
console.logs should return this instead

[]
[ { name: 'min', params: { min: 1 } } ]
[ { name: 'min', params: { min: 1 } } ]
[]
[ { name: 'required', params: undefined } ]
[ { name: 'required', params: undefined } ]

For instance, yup is validating correctly the data when i call validate or validateAt.

Platform (please complete the following information):

  • node v16.17.0
  • yup v1.0.0
@Dauflo Dauflo changed the title Describe not working on conditaionnal validation for yup.array() Describe not working on conditionnal validation for yup.array() Feb 23, 2023
@garyb01
Copy link

garyb01 commented Feb 25, 2023

I have the same issue with all conditionals.

@jquense
Copy link
Owner

jquense commented Feb 25, 2023

please provide a runnable reproduction according the to the template thanks!

@Altroo
Copy link

Altroo commented Feb 27, 2023

Same here, i have an array of images that i need to validate a minimum of one image. my schema is :

images: Yup.array()
    .of(Yup.object().shape({
	 dataURL: Yup.string(),
	 file: Yup.object().nullable().shape({
	 lastModified: Yup.number(),
	 name: Yup.string(),
	 size: Yup.number(),
	 type: Yup.string(),
	 webkitRelativePath: Yup.string(),
       }),
    }),
).min(1, INPUT_IMG_MIN(1)),

INPUT_IMG_MIN is a function .

export const INPUT_IMG_MIN = (char: number) => `Make sure this field has at least ${char} image.`;

I have reverted to the previous version 0.32.11 where it works, i have tried mixed object too didn't work.

When using previous version i can console log the array of images.

image_properties

As you can see the schema works on previous version, but with the new version when using isValid && !isSubmitting the submit button stays disabled.

Any help will be apreciated, i too wanna migrate to v1.
Tested on both 1.0.0 & 1.0.1.

My guess is the problem is not with the conditions, but anything to do with Yup.Array()

@Dauflo
Copy link
Author

Dauflo commented Feb 27, 2023

Here is the codesandbox

https://codesandbox.io/s/relaxed-snowflake-31o2du

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

4 participants