mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
* refactor(r2aform): remove validationData [EE-5559] * update doc --------- Co-authored-by: testa113 <testa113>
19 lines
412 B
TypeScript
19 lines
412 B
TypeScript
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);
|
|
}
|
|
}
|