Skip to content

Commit 2217202

Browse files
1682 Removes reset and cancel button overrides. Removes form history cache when a form flow is finished
1 parent 3034549 commit 2217202

File tree

5 files changed

+11
-25
lines changed

5 files changed

+11
-25
lines changed

frontend/apps/example/src/app/page.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ export default function Home() {
5353
});
5454
};
5555

56-
const ResetButtonAlternative = () => (
57-
<button type="button">Alternative reset</button>
58-
);
59-
60-
const CancelButtonAlternative = () => (
61-
<button type="button">Alternative cancel</button>
62-
);
63-
6456
const componentMatcher = (
6557
currentMatchers: PydanticComponentMatcher[],
6658
): PydanticComponentMatcher[] => {
@@ -98,8 +90,6 @@ export default function Home() {
9890
apiProvider: pydanticFormApiProvider,
9991
labelProvider: pydanticLabelProvider,
10092
customDataProvider: pydanticCustomDataProvider,
101-
resetButtonAlternative: ResetButtonAlternative(),
102-
cancelButton: CancelButtonAlternative(),
10393
componentMatcher: componentMatcher,
10494
}}
10595
/>

frontend/apps/example/src/fields/TextArea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const TextArea: PydanticFormControlledElement = ({
1616
}: PydanticFormControlledElementProps) => {
1717
return (
1818
<textarea
19-
defaultValue={value}
19+
value={value}
2020
onChange={(e) => onChange(e.target.value)}
2121
style={{
2222
width: '450px',

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"scripts": {
4-
"dev": "turbo dev --filter=example",
4+
"dev": "turbo dev",
55
"test": "turbo test",
66
"tsc": "turbo run tsc",
77
"lint": "turbo lint",

frontend/packages/pydantic-forms/src/components/form/Footer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const Footer = () => {
3939
onClick={(e) => {
4040
resetForm(e);
4141
}}
42-
disabled={!rhf.formState.isDirty}
4342
style={{ padding: '4px' }}
4443
>
4544
Reset

frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,10 @@ function PydanticFormContextProvider({
103103

104104
const updateHistory = async (formInput: object, previousSteps: object[]) => {
105105
const hashOfPreviousSteps = await getHashForArray(previousSteps);
106-
107-
console.log('Saving combination', {hashOfPreviousSteps, formInput})
108-
109106
setFormInputHistory((prevState) => prevState.set(hashOfPreviousSteps, formInput));
110-
111107
}
112108

113109
const goToPreviousStep = (formInput: object) => {
114-
console.log('Going back one step');
115110
setFormInputData((prevState) => {
116111
updateHistory(formInput, prevState)
117112
return prevState.slice(0, -1);
@@ -120,7 +115,6 @@ function PydanticFormContextProvider({
120115

121116
const addFormInputData = (formInput: object) => {
122117
setFormInputData((currentInputs) => {
123-
console.log('addFormInputData', { formInput, currentInputs });
124118
updateHistory(formInput, currentInputs)
125119
return [...currentInputs, formInput];
126120
});
@@ -220,6 +214,7 @@ function PydanticFormContextProvider({
220214
}
221215
}
222216

217+
setFormInputHistory(new Map<string, object>());
223218
rhf.reset();
224219
}, [apiResponse, isFullFilled, onSuccess, rhf, skipSuccessNotice]);
225220

@@ -267,12 +262,13 @@ function PydanticFormContextProvider({
267262
const currentStepFromHistory = formInputHistory.get(hash);
268263

269264
if(currentStepFromHistory) {
270-
console.log('Found history', {currentStepFromHistory})
271-
272-
Object.entries(currentStepFromHistory).forEach(([fieldName, fieldValue]) => {
273-
console.log('forEach loop:', {fieldName, fieldValue})
274-
rhf.setValue(fieldName, fieldValue, { shouldDirty: true, shouldTouch: true, shouldValidate: true });
275-
})
265+
Object.entries(currentStepFromHistory)
266+
.forEach(([fieldName, fieldValue]) => rhf.setValue(fieldName, fieldValue, {
267+
shouldDirty: true,
268+
shouldTouch: true,
269+
shouldValidate: true
270+
}
271+
))
276272
}
277273
})
278274
}, [resetFormData]);
@@ -313,6 +309,7 @@ function PydanticFormContextProvider({
313309

314310
const resetForm = useCallback(
315311
(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
312+
// todo reset the history for the current page -- clear all and jump to step 1
316313
e.preventDefault();
317314
resetFormData();
318315
setErrorDetails(undefined);

0 commit comments

Comments
 (0)