File tree Expand file tree Collapse file tree 3 files changed +28
-7
lines changed
frontend/packages/pydantic-forms/src Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Original file line number Diff line number Diff line change 77 */
88import React from 'react' ;
99
10+ import Link from 'next/link' ;
11+
1012import { componentMatcher } from '@/components/componentMatcher' ;
1113import Footer from '@/components/form/Footer' ;
1214import RenderFormErrors from '@/components/render/RenderFormErrors' ;
@@ -27,7 +29,14 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
2729 headerComponent,
2830 skipSuccessNotice,
2931 loadingComponent,
32+ clearForm,
3033 } = contextProps ;
34+ const {
35+ formRenderer,
36+ footerRenderer,
37+ componentMatcher : customComponentMatcher ,
38+ resetAfterSubmit,
39+ } = config || { } ;
3140
3241 const LoadingComponent = loadingComponent ?? (
3342 < div > Formulier aan het ophalen...</ div >
@@ -42,20 +51,22 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
4251 }
4352
4453 if ( isFullFilled ) {
54+ if ( resetAfterSubmit ) {
55+ clearForm ( ) ;
56+ }
57+
4558 if ( skipSuccessNotice ) {
4659 return < > </ > ;
4760 }
4861
4962 return (
50- < div > { successNotice ?? 'Je inzending is succesvol ontvangen' } </ div >
63+ < div >
64+ { successNotice ?? 'Je inzending is succesvol ontvangen' }
65+ < Link href = "/" > overnieuw</ Link >
66+ </ div >
5167 ) ;
5268 }
5369
54- const {
55- formRenderer,
56- footerRenderer,
57- componentMatcher : customComponentMatcher ,
58- } = config || { } ;
5970 const Renderer = formRenderer ?? FormRenderer ;
6071 const FooterRenderer = footerRenderer ?? Footer ;
6172
Original file line number Diff line number Diff line change @@ -312,6 +312,12 @@ function PydanticFormContextProvider({
312312 isParsingSchema ||
313313 ( customDataProvider ? isLoadingCustomData : false ) ;
314314
315+ const clearForm = useCallback ( ( ) => {
316+ setFormInputData ( [ ] ) ;
317+ setIsFullFilled ( false ) ;
318+ setRawSchema ( undefined ) ;
319+ } , [ ] ) ;
320+
315321 const PydanticFormContextState = {
316322 // to prevent an issue where the sending state hangs
317323 // we check both the SWR hook state as our manual state
@@ -340,6 +346,7 @@ function PydanticFormContextProvider({
340346 setSaveToLeavePageInCurrentState,
341347 formKey,
342348 formIdKey,
349+ clearForm,
343350 } ;
344351
345352 return (
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ export interface PydanticFormInitialContextProps {
3030 footerComponent ?: React . ReactNode ;
3131 loadingComponent ?: React . ReactNode ;
3232 hasCardWrapper ?: boolean ;
33-
3433 config : PydanticFormsContextConfig ;
3534}
3635
@@ -75,6 +74,8 @@ export interface PydanticFormContextProps {
7574 config ?: PydanticFormsContextConfig ;
7675 formKey : string ;
7776 formIdKey ?: string ;
77+ clearForm : ( ) => void ;
78+ resetAfterSubmit ?: boolean ;
7879}
7980
8081export enum PydanticFormState {
@@ -307,6 +308,8 @@ export interface PydanticFormsContextConfig {
307308
308309 // have an option to change the layout columns of fields
309310 formStructureMutator ?: PydanticFormStructureMutator ;
311+
312+ resetAfterSubmit ?: boolean ;
310313}
311314
312315export type FormRenderer = React . JSXElementConstructor < {
You can’t perform that action at this time.
0 commit comments