1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 21:39:40 +02:00
portainer/app/react/components/form-components/validate-form.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

20 lines
412 B
TypeScript
Raw Normal View History

import { yupToFormErrors } from 'formik';
import { SchemaOf } from 'yup';
export async function validateForm<T>(
schemaBuilder: () => SchemaOf<T>,
formValues: T
) {
const validationSchema = schemaBuilder();
try {
await validationSchema.validate(formValues, {
strict: true,
abortEarly: false,
});
return undefined;
} catch (error) {
return yupToFormErrors<T>(error);
}
}