jquense / react-formal

Sophisticated HTML form management for React
http://jquense.github.io/react-formal
MIT License
527 stars 52 forks source link

Validation is not run on NestedForms #182

Open samboylett opened 2 years ago

samboylett commented 2 years ago

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

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!