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

Custom objet validation with early : false failed #2241

Open
Syfele opened this issue Aug 9, 2024 · 2 comments
Open

Custom objet validation with early : false failed #2241

Syfele opened this issue Aug 9, 2024 · 2 comments

Comments

@Syfele
Copy link

Syfele commented Aug 9, 2024

I have an object to validate that I build in several steps (step 1, step 2 ...) and in one of the steps there is drag and drop on several dynamic elements and forms in modals which make the use of classic forms very difficult.

All this to say that I validate an object and not a form

my object is built well with empty fields and it is filled if the user does actions ....

at the time of validation I use { abortEarly: false } (to have all the error messages) but unfortunately I only receive the first error message, and I have to correct what's wrong to get the next error message

I read @jquense's answers everywhere where he explains that abortEarly does not mean to execute the validations in parallel and return the result as soon as possible, but rather to wait for the validation to be finished to have a result

When I click on my button, my object is ready for validation and I do not know what to do to display all the messages to the user at once

Help Others Reproduce
It is too hard to create a sandbox as I need to copy many components to work correctly, as I said there is a drag and drop events and modal forms

Here is my validation callback

const validateSecondStep = () => {
    yupSecondStepSchema.validate(object)
        .then((v) => {console.log(object);}, {abortEarly: false})
        .catch((err) => {console.log(err.errors);})
}

And here is my yupSecondStepSchema

const yupSecondStepSchema = Yup.object().shape({
    days: Yup.array(
        Yup.object({
            sessions: Yup.array(
                Yup.object({
                    hour: Yup.string().required(),
                    sets: Yup.array(
                        Yup.object({
                            label: Yup.object().required(),
                            reference: Yup.string().required(),
                            value: Yup.string().required()
                        })
                    ).min(1) // a session must have at least one set
                })
            )
        })
    )
});
)

I confirm that the first time I get

['days[0].sessions[0].hour is a required field']

I must set hour to session to get

['days[0].sessions[0].sets field must have at least 1 items']

My Object structure :

{
    days: [
        {
            dayNumber: 1,
            sessions: [
                {
                    hour: null,
                    sets: [
                        {
                            label: string,
                            reference: string,
                            value: number
                        }
                    ]
                }
            ]
        }
    ]
}

Any help will be a pleasure

@Syfele
Copy link
Author

Syfele commented Aug 14, 2024

No one has anything to tell ?

@jquense
Copy link
Owner

jquense commented Aug 26, 2024

I don't really know what you are asking about here, there isn't really a specific issue demonstrated that I can tell sorry. Schema look fine if your getting different results it might be due to the code calling the schema

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