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

Validation is not run on NestedForms #182

Open
samboylett opened this issue Mar 29, 2022 · 1 comment
Open

Validation is not run on NestedForms #182

samboylett opened this issue Mar 29, 2022 · 1 comment

Comments

@samboylett
Copy link

I have a yup object with a custom validation (test) which relies on the entire object. As validation is only triggered on changing fields, this test is never ran. It would be good if there was a way to trigger validation on the entire form/nested form. (e.g. add the validateOn/noValidate props to Form/NestedForm).

For now I have done this as a work around (code is copied from NestedForm and modified so it will run the validation on it):

    const [, meta] = useField(name);

    return (
      <Form
        as="div"
        schema={schema}
        value={meta.value}
        onChange={meta.onChange}
        onError={(nextErrors) => meta.onError(prefix(nextErrors, name))}
        errors={unprefix(meta.errors, name)}
        context={meta.context}
      >

Thanks!

@samboylett
Copy link
Author

I've rewritten NestedForm for my project now, it takes nameOrOptions as string | UseFieldOptions and also handles a few other things around validation to get it to work correctly. Happy to put in a PR for this!

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

1 participant