You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/components/form-components/validate-form.ts

20 lines
412 B

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);
}
}