Skip to content

Commit

Permalink
feat(ui-commons): add allowSubmitOnPristine prop in Form
Browse files Browse the repository at this point in the history
  • Loading branch information
skamril committed Oct 4, 2024
1 parent 04f0c2d commit 5302e32
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions webapp/src/components/common/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export interface FormProps<
hideFooterDivider?: boolean;
onStateChange?: (state: FormState<TFieldValues>) => void;
autoSubmit?: boolean | AutoSubmitConfig;
allowSubmitOnPristine?: boolean;
enableUndoRedo?: boolean;
sx?: SxProps<Theme>;
apiRef?: React.Ref<UseFormReturnPlus<TFieldValues, TContext> | undefined>;
Expand All @@ -119,6 +120,7 @@ function Form<TFieldValues extends FieldValues, TContext>(
hideFooterDivider,
onStateChange,
autoSubmit,
allowSubmitOnPristine,
enableUndoRedo,
className,
sx,
Expand Down Expand Up @@ -173,7 +175,7 @@ function Form<TFieldValues extends FieldValues, TContext>(
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;
Expand Down Expand Up @@ -296,8 +298,8 @@ function Form<TFieldValues extends FieldValues, TContext>(
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) => {
Expand Down

0 comments on commit 5302e32

Please sign in to comment.