scroll to required fields in trail edit

Former-commit-id: 4d4c11bd86760b9ee98b7db188df279cf71e82d1
This commit is contained in:
Christian Beutel
2024-03-15 13:42:27 +01:00
parent fa50aa01ea
commit f33a4d13f7
6 changed files with 309 additions and 425 deletions

View File

@@ -28,6 +28,7 @@ export const createForm = (config) => {
const validationSchema = config.validationSchema;
const validateFunction = config.validate;
const onSubmit = config.onSubmit;
const onError = config.onError;
const getInitial = {
values: () => util.cloneDeep(initialValues),
@@ -133,6 +134,7 @@ export const createForm = (config) => {
return clearErrorsAndSubmit(values);
} else {
errors.set(error);
onError(error)
isSubmitting.set(false);
}
})
@@ -154,7 +156,7 @@ export const createForm = (config) => {
yupErrors.inner.map((error) =>
util.set(updatedErrors, error.path, error.message),
);
onError(updatedErrors)
errors.set(updatedErrors);
}
isSubmitting.set(false);

View File

@@ -61,6 +61,7 @@ type FormState<Inf = Record<string, any>> = {
declare function createForm<Inf = Record<string, any>>(formProperties: {
initialValues: Inf;
onSubmit: (values: Inf) => any | Promise<any>;
onError?: (errors: Record<string, any>) => any | Promise<any>;
validate?: (values: Inf) => any | undefined;
validationSchema?: ObjectSchema<any>;
}): FormState<Inf>;