Skip to content

Commit

Permalink
feat: FormBase clears the extraErrors on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-foucault committed Jun 9, 2022
1 parent 7e3262f commit 5ace198
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/components/Form/FormBase.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import formTheme from "lib/theme/FormWithTheme";
import { forwardRef, useEffect, useMemo, useState } from "react";
import { FormProps, AjvError, withTheme } from "@rjsf/core";
import { FormEvent, forwardRef, useEffect, useMemo, useState } from "react";
import { FormProps, AjvError, withTheme, ISubmitEvent } from "@rjsf/core";
import validateFormData from "@rjsf/core/dist/cjs/validate";
import { customTransformErrors } from "lib/theme/customTransformErrors";
import {
Expand Down Expand Up @@ -38,7 +38,20 @@ const FormBase: React.ForwardRefRenderFunction<any, FormPropsWithTheme<any>> = (
).errorSchema
);
}
}, []);
}, [props.schema, props.validateOnMount]);

const handleSubmit = (
e: ISubmitEvent<any>,
nativeEvent: FormEvent<HTMLFormElement>
) => {
setExtraErrors(undefined);
props.onSubmit?.(e, nativeEvent);
};

const handleError = (e: any) => {
setExtraErrors(undefined);
props.onError?.(e);
};

return (
<>
Expand All @@ -53,6 +66,8 @@ const FormBase: React.ForwardRefRenderFunction<any, FormPropsWithTheme<any>> = (
omitExtraData
showErrorList={false}
tagName={props.tagName}
onSubmit={handleSubmit}
onError={handleError}
></Form>
<style jsx>{`
:global(label) {
Expand Down

0 comments on commit 5ace198

Please sign in to comment.