zaguiini / formik-wizard

A multi-step form component powered by formik and react-albus
MIT License
86 stars 26 forks source link

Documentation for resetting form on submit #15

Closed Hopp3r closed 4 years ago

Hopp3r commented 4 years ago

@zaguiini I want to reset the form on submit. I use setValues from useFormikWizard, but now that data persists even upon submitting my form. How do I clear my values for the next use of the wizard?

const { values: wizardValues } = useFormikWizard();
const [tableData, setTableData] = useState(wizardValues.lineItems.data != null ? wizardValues.lineItems.data : [] );

Specifically doing something like this persists, even after submit. The next time I open the wizard, tableData is populated with my old lineitems data.

zaguiini commented 4 years ago

If you change the steps value it will reset the form values. Closing as this is not related to the library itself but an use case that would be better asked on Stack Overflow.

ataravati commented 4 years ago

@zaguiini What do you mean change the steps value?

Hopp3r commented 4 years ago

a code example would be nice, i was never able to figure this out

ataravati commented 4 years ago

@Hopp3r I got it. Just create a state for your steps and tie the steps property of the wizard to it. Then, you'll just need to set the state in order to reset the form values.

ataravati commented 4 years ago

@zaguiini Changing the steps doesn't reset the form. I tried that. It resets the form values, of course, but the wizard remains at the last step. And, there's no function to go to the first step, is that right?

zaguiini commented 4 years ago

Yes, that's probably correct as it's not really a common case. It's actually possible to go to a specific step if you pass the correct albusProps.

ataravati commented 4 years ago

@zaguiini Well, in fact, the only scenario I can think of, in which you don't want to reset the form, is a sign-up wizard. So, I would say having to reset the form is very common.

I saw the go() method of albusProps. It doesn't work after the form is submitted. I'm going to try it, at the time the steps are loaded.