@@ -295,6 +295,40 @@ function PydanticFormContextProvider({
295295 // eslint-disable-next-line react-hooks/exhaustive-deps
296296 } , [ apiResponse ] ) ; // Avoid completing the dependencies array here to avoid unwanted resetFormData calls
297297 // a useeffect for filling data whenever formdefinition or labels update
298+
299+ // When a formKey changes we reset the form input data
300+ useEffect ( ( ) => {
301+ if ( formKey !== formRef . current ) {
302+ console . log ( 'formchange' , formKey , formRef . current ) ;
303+ // When the formKey changes we need to reset the form input data
304+ setFormInputData ( [ ] ) ;
305+ setFormInputHistory ( new Map < string , object > ( ) ) ;
306+ awaitReset ( ) ;
307+ formRef . current = formKey ;
308+ }
309+ } , [ awaitReset , formKey ] ) ;
310+
311+ // handle successfull submits
312+ useEffect ( ( ) => {
313+ if ( ! isFullFilled ) {
314+ return ;
315+ }
316+
317+ if ( onSuccess ) {
318+ const values = rhf . getValues ( ) ;
319+ if ( skipSuccessNotice ) {
320+ onSuccess ( values , apiResponse || { } ) ;
321+ } else {
322+ setTimeout ( ( ) => {
323+ onSuccess ?.( values , apiResponse || { } ) ;
324+ } , 1500 ) ; // Delay to allow notice to show first
325+ }
326+ }
327+
328+ setFormInputHistory ( new Map < string , object > ( ) ) ;
329+ // eslint-disable-next-line react-hooks/exhaustive-deps
330+ } , [ apiResponse , isFullFilled ] ) ;
331+
298332 return (
299333 < PydanticFormContext . Provider value = { PydanticFormContextState } >
300334 { children ( PydanticFormContextState ) }
0 commit comments