From 5302e3222ffe6fc73e9bc479048190ed684e497d Mon Sep 17 00:00:00 2001 From: Samir Kamal <1954121+skamril@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:01:58 +0200 Subject: [PATCH] feat(ui-commons): add `allowSubmitOnPristine` prop in Form --- webapp/src/components/common/Form/index.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/webapp/src/components/common/Form/index.tsx b/webapp/src/components/common/Form/index.tsx index da4bcca048..fe3178cba1 100644 --- a/webapp/src/components/common/Form/index.tsx +++ b/webapp/src/components/common/Form/index.tsx @@ -94,6 +94,7 @@ export interface FormProps< hideFooterDivider?: boolean; onStateChange?: (state: FormState) => void; autoSubmit?: boolean | AutoSubmitConfig; + allowSubmitOnPristine?: boolean; enableUndoRedo?: boolean; sx?: SxProps; apiRef?: React.Ref | undefined>; @@ -119,6 +120,7 @@ function Form( hideFooterDivider, onStateChange, autoSubmit, + allowSubmitOnPristine, enableUndoRedo, className, sx, @@ -173,7 +175,7 @@ function Form( formState; // Don't add `isValid` because we need to trigger fields validation. // In case we have invalid default value for example. - const isSubmitAllowed = isDirty && !isSubmitting; + const isSubmitAllowed = (isDirty || allowSubmitOnPristine) && !isSubmitting; const rootError = errors.root?.[ROOT_ERROR_KEY]; const showSubmitButton = !hideSubmitButton && !autoSubmitConfig.enable; const showFooter = showSubmitButton || enableUndoRedo || rootError; @@ -296,8 +298,8 @@ function Form( return Promise.all(toResolve) .then((values) => { submitSuccessfulCb.current = () => { - const onSubmitRes = onSubmit ? R.last(values) : undefined; - onSubmitSuccessful?.(dataArg, onSubmitRes); + const submitRes = onSubmit ? R.last(values) : undefined; + onSubmitSuccessful?.(dataArg, submitRes); }; }) .catch((err) => {