mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
Fixed bug on resetting the form component
This commit is contained in:
parent
b7444fb3ed
commit
708c2e3a7d
2 changed files with 12 additions and 3 deletions
|
|
@ -80,7 +80,7 @@ export const Form = function Form(props) {
|
|||
};
|
||||
setExposedVariables(exposedVariables);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isValid]);
|
||||
}, [isValid, formEvents]);
|
||||
|
||||
const extractData = (data) => {
|
||||
const result = {};
|
||||
|
|
@ -183,7 +183,7 @@ export const Form = function Form(props) {
|
|||
document.addEventListener('submitForm', handleFormSubmission);
|
||||
return () => document.removeEventListener('submitForm', handleFormSubmission);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [buttonToSubmit, isValid, advanced, JSON.stringify(uiComponents)]);
|
||||
}, [buttonToSubmit, isValid, advanced, JSON.stringify(uiComponents), formEvents]);
|
||||
|
||||
const handleSubmit = (event) => {
|
||||
event.preventDefault();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import React from 'react';
|
||||
import React, { useState, useCallback } from 'react';
|
||||
import { getComponentToRender } from '@/_helpers/editorHelpers';
|
||||
import _ from 'lodash';
|
||||
|
||||
|
|
@ -36,9 +36,18 @@ export const shouldUpdate = (prevProps, nextProps) => {
|
|||
};
|
||||
|
||||
const ComponentWrapper = React.memo(({ componentName, ...props }) => {
|
||||
const [key, setKey] = useState(Math.random());
|
||||
|
||||
const resetComponent = useCallback(() => {
|
||||
setKey(Math.random());
|
||||
}, []);
|
||||
|
||||
const ComponentToRender = getComponentToRender(componentName);
|
||||
|
||||
if (ComponentToRender === null) return;
|
||||
if (componentName === 'Form') {
|
||||
return <ComponentToRender key={key} resetComponent={resetComponent} {...props} />;
|
||||
}
|
||||
|
||||
return <ComponentToRender {...props} />;
|
||||
}, shouldUpdate);
|
||||
|
|
|
|||
Loading…
Reference in a new issue